简体   繁体   English

jQuery Ajax成功回调没有触发也没有返回错误

[英]jQuery Ajax success callback not firing nor returning error

I have the follow POST request that isn't firing the success function nor is it giving me an error: 我有跟随POST请求,但没有触发成功函数,也没有给我一个错误:

$.ajax({
        type: 'POST',
        url: '/api/me',
        data: {
            z_num: $("#selectEmployee").val()
        },
        success: function(data) {
            console.log('done post')
        },
        error: function(error) {
            console.log(error);
        }
    });

I know for a fact the request works because it sends z_num to the server for a database update (the database actually does get updated) so I'm not sure why it's not firing the success function... anyone have any idea what's going on? 我知道这个请求是有效的,因为它将z_num发送到服务器进行数据库更新(数据库实际上确实更新了)所以我不确定为什么它没有触发成功函数...任何人都知道发生了什么?

Under some circumstances your server might not return the response correctly. 在某些情况下,您的服务器可能无法正确返回响应。 Have you tried to handle the actual response code (eg if your server returns 200) like this: 您是否尝试过处理实际的响应代码(例如,如果您的服务器返回200),如下所示:

 $.ajax({
         type: 'POST', 
         url : '/api/me',
         data: { z_num: $("#selectEmployee").val()},
         statusCode: {
               200: function (response) {
                      // do your stuff here
                    }
         }
 });

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

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