简体   繁体   English

Ajax调用没有错误但不起作用

[英]Ajax call no error but does not work

Here my Ajax Call and it does not produce any error but it does not call the php file (I can see it in the network tab of my chrome, and when I call it in the javascript console, it's does return false as expected : 在这里我的Ajax调用,它不会产生任何错误,但它不会调用php文件(我可以在我的chrome的网络选项卡中看到它,当我在javascript控制台中调用它时,它会按预期返回false:

 function submitData() {
    $('#sortable2').sortable({
        axis: 'y',
        update: function(event, ui) {
            var data = $(this).sortable('serialize');
            $.ajax({
                data: data,
                type: 'POST',
                url: './post_occupation_data.php'
            });
        }
    });
    return false;
}

Thank you 谢谢

Try this code and and check the if you are getting alert messages are not.. if 404 alert message please check your URL 尝试此代码,并检查您是否收到警报消息..如果404警告消息,请检查您的URL

  function submitData() {
    $('#sortable2').sortable({
        axis: 'y',
        update: function(event, ui) {
            var data = $(this).sortable('serialize');
            $.ajax({
                data: data,
                type: 'POST',
                url: './post_occupation_data.php',
                error: function (xhr, ajaxOptions, thrownError) {
                       alert(xhr.status);
                      alert(thrownError);
                      },
              success: function(result){
                    alert(result);
                  }
            });
        }
    });
    return false;
}

try to stringify the parameter like below 尝试将参数字符串化,如下所示

data: JSON.stringify(data)

Also add below parameters in your ajax call 还要在ajax调用中添加以下参数

contentType: "application/json; charset=utf-8",
dataType: "json",

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM