I want the user to fill it out. Submit it, have it store into the database and then use jquery to have it show up on the same page in front of them. Right now I can get it to se
Here is another way, if you use the serialize function built into jquery along with the $.post you won't have to actually write much code.
html form and html displaying the messages:
Type here: Some old message Some other old message jquery to send the new messages to your server from the client and placing new message into the DOM and resetting the html form //bind a click even to the submit $('.commentForm input[type=submit]').click(function(){ $(this).closest('form').find('input[type=submit]').value('Submitting'); $.post( $(this).closest('form').attr('action'), $(this).closest('form').serialize(), function(responseFromServer){ //get the message from the html form (don't need to send it back from the server) var message = $(this).closest('form').find('textarea'); $('.messages').append(''+message+''); //resetting the html form $(this).closest('form').find('textarea').html(''); $(this).closest('form').find('input[type=submit]').value('Submit'); } ); //prevent the form from actually sending in the standard fashion by returning false return false; }); php //get the post variable and make it safe for inputting into the db $message = mysql_real_escape_string(html_entities($_POST['story'])); if(!empty($message)){ //assuming you have a db connection $insert_query = mysql_query("INSERT INTO textwalltable VALUES($message)"); echo 'message entered'; } else { echo 'no message'; } 0 讨论(0) 查看其它3个回答 发布评论: 提交评论 加载中... 验证码 看不清? 提交回复
jquery to send the new messages to your server from the client and placing new message into the DOM and resetting the html form
//bind a click even to the submit $('.commentForm input[type=submit]').click(function(){ $(this).closest('form').find('input[type=submit]').value('Submitting'); $.post( $(this).closest('form').attr('action'), $(this).closest('form').serialize(), function(responseFromServer){ //get the message from the html form (don't need to send it back from the server) var message = $(this).closest('form').find('textarea'); $('.messages').append(''+message+''); //resetting the html form $(this).closest('form').find('textarea').html(''); $(this).closest('form').find('input[type=submit]').value('Submit'); } ); //prevent the form from actually sending in the standard fashion by returning false return false; });
php
//get the post variable and make it safe for inputting into the db $message = mysql_real_escape_string(html_entities($_POST['story'])); if(!empty($message)){ //assuming you have a db connection $insert_query = mysql_query("INSERT INTO textwalltable VALUES($message)"); echo 'message entered'; } else { echo 'no message'; }