Created
July 19, 2013 02:07
-
-
Save sivagao/6034561 to your computer and use it in GitHub Desktop.
ubmit multiple forms with jQuery and Ajax.
http://www.9lessons.info/2009/06/submit-multiple-forms-jquery-ajax.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="loadplace<?php echo $msg_id; ?>"></div> | |
<div id="flash<?php echo $msg_id; ?>"></div> | |
<div class='panel' id="slidepanel<?php echo $msg_id; ?>"> | |
<form action="" method="post" name="<?php echo $msg_id; ?>"> | |
<textarea id="textboxcontent<?php echo $msg_id; ?>" ></textarea><br /> | |
<input type="submit" value=" Comment_Submit " class="comment_submit" id="<?php echo $msg_id; ?>" /> | |
</form> | |
</div> | |
// insertjax.php | |
<?php | |
if(isSet($_POST['textcontent']){ | |
$textcontent = $_POST['textcontent']; | |
}) | |
?> | |
<div class="loading_comment"> | |
<?php echo $textcontent; ?> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function(){ | |
$('.comment_submit').click(function(){ | |
var ele = $(this); | |
var id = ele.attr('id'); | |
var text = $('#textboxcontent'+id).val(); | |
var dataString = 'textcontent=' + text + '&com_msgid' + id; | |
if(text == ''){ | |
alert('please enter some text to comment'); | |
return; | |
} | |
$('#flash'+id).show(); | |
$('#flash'+id).fadeIn(400).html('<img src="ajax-loading.gif" align="absmiddle"> loading.... '); | |
$.ajax({ | |
'type': 'POST', | |
'url': 'insertjax.php', | |
'data': dataString, | |
cache: false, | |
success: function(html){ | |
$('#flash'+id).hide(); | |
$('#loadplace'+id).append(html); | |
} | |
}); | |
return false; | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment