Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/443.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
Javascript 使用AJAX停留在同一页面时出现未知错误_Javascript_Php_Jquery_Ajax - Fatal编程技术网

Javascript 使用AJAX停留在同一页面时出现未知错误

Javascript 使用AJAX停留在同一页面时出现未知错误,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,接下来,我尝试了一个新的AJAX代码,但仍然得到了相同的结果(数据插入正确,但不能停留在同一页面中) 表单中有一个id=“form1”,表单中的提交按钮是id=“insert” 非常感谢您的帮助,请立即修复。在关闭AJAX函数之前,应先关闭success函数。您忘了添加结束符}: $(function(){ $("#form1").on("submit", function(e){ $.ajax({ url: 'insert.php', type: 'pos

接下来,我尝试了一个新的AJAX代码,但仍然得到了相同的结果(数据插入正确,但不能停留在同一页面中)

表单中有一个
id=“form1”
,表单中的提交按钮是
id=“insert”


非常感谢您的帮助,请立即修复。

在关闭AJAX函数之前,应先关闭
success
函数。您忘了添加结束符
}

$(function(){
  $("#form1").on("submit", function(e){
    $.ajax({
      url: 'insert.php',
      type: 'post',
      data: $('#form1').serialize(),
      dataType: 'json',
      success: function(data) {
        alert($('#form1').serialize() + "&insert=yes"); // add this
      } //<--------------------------------------- You missed this
    });
    e.preventDefault();
  });
});
$(函数(){
$(“#表格1”)。关于(“提交”,功能(e){
$.ajax({
url:'insert.php',
键入:“post”,
数据:$('#form1')。序列化(),
数据类型:“json”,
成功:功能(数据){
警报($('#form1').serialize()+“&insert=yes”);//添加此

}//可能在控制台中引发错误,导致代码无法正常工作。否,控制台为空,未显示任何错误
$(function(){
  $("#form1").on("submit", function(e){
    $.ajax({
      url: 'insert.php',
      type: 'post',
      data: $('#form1').serialize(),
      dataType: 'json',
      success: function(data) {
        alert($('#form1').serialize() + "&insert=yes"); // add this
      } //<--------------------------------------- You missed this
    });
    e.preventDefault();
  });
});