I have the following Ajax code within jQuery that uses a save.php page to save data from a form to the MySQL database:
$('#frmSurvey').append("<input type='hidden' name='page' value='"+$page+"' />"); // NOTE: this is done before the submit.
document.frmSurvey.submit(); // There is some validation done and then the submit is called
var url = "save.php"; // the script where you handle the form input.
$.ajax({
type: "POST",
url: url,
data: $("#frmSurvey").serialize(), // serializes the form's elements.
success: function(data)
{
alert(data); // show response from the php script.
}
});
And the HTML:
<form id="frmSurvey" name="frmSurvey" action="save.php" method="post" onsubmit="return false">
Hope that all makes sense.
I understood that the Ajax call to the save.php page would mean that the users doesn't see the page and it happens in the background. However, the save.php page still appears in the web address bar for a second or two - is this correct - any way to stop this happening?