Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery Ajax保存-页面显示/页面闪烁_Jquery_Ajax_Browser - Fatal编程技术网

jQuery Ajax保存-页面显示/页面闪烁

jQuery Ajax保存-页面显示/页面闪烁,jquery,ajax,browser,Jquery,Ajax,Browser,jQuery中有以下Ajax代码,它使用save.php页面将表单中的数据保存到MySQL数据库: $('#frmSurvey').append("<input type='hidden' name='page' value='"+$page+"' />"); // NOTE: this is done before the submit. document.frmSurvey.submit(); // There is some validation done a

jQuery中有以下Ajax代码,它使用save.php页面将表单中的数据保存到MySQL数据库:

    $('#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.
           }
         });
$('frmSurvey')。附加(“”;//注意:这是在提交之前完成的。
document.frmSurvey.submit();//完成一些验证,然后调用submit
var url=“save.php”;//处理表单输入的脚本。
$.ajax({
类型:“POST”,
url:url,
数据:$(“#frmSurvey”).serialize(),//序列化表单的元素。
成功:功能(数据)
{
警报(数据);//显示来自php脚本的响应。
}
});
以及HTML:

<form id="frmSurvey" name="frmSurvey" action="save.php" method="post" onsubmit="return false">

希望一切都有意义


我知道,对save.php页面的Ajax调用意味着用户看不到该页面,而是发生在后台。但是,save.php页面仍然会在web地址栏中出现一两秒钟-这是否正确-有什么方法可以阻止这种情况发生吗?

导航到另一个URL是因为您实际上正在使用
document.frmSurvey.submit()进行AJAX调用之前进行正确的表单提交--事实上,这将阻止AJAX请求发生,因为导航到表单操作URL将停止当前页面的JS处理


如果删除该行,您的表单将通过AJAX提交,而不需要任何重定向。

看到包装您发布内容的代码会很有趣。也许您在
submit
处理程序中执行此操作,但忘记取消默认的提交操作?请同时发布表单的HTML。正如Jon所说,让我们看看是什么调用此函数的。您的代码可能正在更改URL。默认情况下,这不是$的行为。AjaxThank all-您已经用进一步的信息更新了问题。@荷马:嗯,您是在AJAX请求之前直接提交表单的。事实上,AJAX根本不会发生,因为提交表单会强制立即导航到表单
action
URL(瞬间的URL更改可能是因为表单目标上完成了)。你为什么这么做?