Page Refresh Instead Of Ajax Load Without
On form submit i want to load a div with an updated list of a mysql table. I'am sending the form variables across to a php and posting them into a mysql table. the same page displa
Solution 1:
You need to prevent the form from redirecting the page using the preventDefault
method on the event object:
$("#formSubmit").submit(function(e){ // add the event object as an argument to your function
e.preventDefault(); // right herevar name = $("input#name").val();
var comment = $("input#comment").val();
var filmnumber = $("input#hidden").val();
var dataString = 'name='+ name + '&comment=' + comment + '&filmnumber=' + filmnumber;
$.ajax({
type: "POST",
url: "comment.php",
data: dataString,
success: function() {
$('#2').load('comment.php');
}
});
});
Solution 2:
add a return false to the end to stop the form from submitting. or if you want to be more elegant use the preventDefault(); method. personally for something as simple as this though i just stick with return false;
$("#formSubmit").submit(function(e){ // add the event object as an argument to your functionvar name = $("input#name").val();
var comment = $("input#comment").val();
var filmnumber = $("input#hidden").val();
var dataString = 'name='+ name + '&comment=' + comment + '&filmnumber=' + filmnumber;
$.ajax({
type: "POST",
url: "comment.php",
data: dataString,
success: function() {
$('#2').load('comment.php');
}
});
returnfalse;//right here
});
Post a Comment for "Page Refresh Instead Of Ajax Load Without"