简体   繁体   English

Ajax成功对我不起作用

[英]Ajax success not working for me

follow code is supposed to show alert msg. 遵循代码应该显示警报消息。 It is doing nothing. 它什么也没做。 Can anyone tell me where I am wrong. 谁能告诉我我错了。 Everything is working nicely execpt alert(). 一切运行良好execpt alert()。

<script>
      $(document).ready(function(){
    var baseUrl = document.location.origin;

 $(".ProductRemove").click(function(){
   var row_id = $(this).attr('id');
 $.ajax({
    type:"POST",
    cache:false,
    url:baseUrl+"/shop/api/cart",
    data:"row_id="+row_id+"&action=remove",    // multiple data sent using ajax
    success: function () {

          alert('success');

    },
    error: function(){
   alert('failure');
 }
  });
  });
});

Thanks to all, I got the solution. 感谢所有人,我找到了解决方案。 It is calling error function instead of success because I am returning in nothing from the server. 它正在调用错误函数而不是成功,因为我没有从服务器返回任何东西。

In ajax empty is not considered as JSON data. 在ajax中,空白不被视为JSON数据。 So to fix that I have to echo "json_encode(NULL);" 因此,要解决此问题,我必须回显“ json_encode(NULL);” in my server. 在我的服务器上。

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

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