JQuery的:AJAX错误:获取发送到服务器的数据 [英] JQuery: AJAX error: get data sent to server

查看:149
本文介绍了JQuery的:AJAX错误:获取发送到服务器的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这应该是简单的,但我无法找到的信息就如何做到这一点的任何地方:

This should be simple, but I can't find info anywhere on how to do it:

$.ajax({
    type: 'POST',
    url: 'addToBasket.php',
    data: 'id='+id,
    // ....
    error: function(xhr, textStatus, error){
        // how to get the id sent to the server?
    },
    success: function(data, textStatus, xhr){}
});

如何能在错误处理功能的访问请求发送到服务器中的数据?

How can the error handling function access the data sent to the server in the request?

推荐答案

您可以用全局错误处理程序来获取数据对象。
这将触发对所有的Ajax错误,但可以通过网址或通过任何其他选项

You can use the global error handler to get the data object.
It will fire on all ajax errors, but can be filtered by URL or any other option passed

$(document).ajaxError(function(event, jqXHR, ajaxSettings, thrownError) {
    if (ajaxSettings.url == 'addToBasket.php') {
        alert(ajaxSettings.data)
    }
});

FIDDLE

这篇关于JQuery的:AJAX错误:获取发送到服务器的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆