繁体   English   中英

jQuery ajax不发送请求

[英]jquery ajax does not send request

我的以下代码有问题。

var sendJson = (JSON.stringify(comanda));

$.ajax({
    url: 'sendMail.php',
    type : "post",
    data: sendJson,
    success: function(data){
        alert("Comanda dumneavoastra a fost trimisa");
    }
}); 

好像没有发送数据。。。为什么?

好的...我什么都不知道,因为我使用Firebug监视请求。 我没有错误,控制台也没有。 检查它是否被激活。

这就是我的评论意思:

var sendJson = (JSON.stringify(comanda));

$.ajax({
    url: '/resource_url_goes_here',
    type : 'POST',
    data: sendJson,
    success: function(data){
        /* implementation goes here */ 
    },
    error: function(jqXHR, textStatus, errorThrown) { 
        /* implementation goes here */ 
    }
}); 

请注意,ajax请求现在有一个error回调。 所有请求都应具有错误回调,以便您可以轻松识别何时发生错误(如您所见,firebug不能捕获所有内容)。

有时对我有用的另一件事是StatusCodes

$.ajax({
    url: '/resource_url_goes_here',
    type : 'POST',
    data: sendJson,
    statusCode: {  
        404: function() {  
            /*implementation for HTTP Status 404 (Not Found) goes here*/
        },
        401: function() {  
            /*implementation for HTTP Status 401 (Unauthorized) goes here*/
        } 
    },
    success: function(data){
        /* implementation goes here */ 
    },
    error: function(jqXHR, textStatus, errorThrown) { 
        /* implementation goes here */ 
    }
});

当服务器返回特定的状态代码时(此代码段中的404和401),这将执行一个功能,并且您可以为所需的状态代码指定特定的处理程序。 您可以在这里找到更多关于此的信息

暂无
暂无

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

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