gpt4 book ai didi

jquery - 在 dataFilter 中捕获 http 代码状态

转载 作者:行者123 更新时间:2023-12-01 04:57:54 33 4
gpt4 key购买 nike

我如何在 dataFilter 中捕获 http 代码状态?有以下代码:

$.ajaxSetup ({
dataFilter: function (data) {
//need know http status for change data

return data;
}
});

最佳答案

您无法使用 dataFilter 来执行此操作。来自文档:

dataFilter(data, type)Function A function to be used to handle the raw response data of XMLHttpRequest.This is a pre-filtering function to sanitize the response. You should return the sanitized data. The function accepts two arguments: The raw data returned from the server and the 'dataType' parameter.

加上您引用的ajaxSetup,用于定义进行 jQuery ajax 调用时的默认 ajax 设置。该代码实际上并没有进行 ajax 调用。

jQuery ajax 方法有一个 statusCode 属性,其中包含您要查找的内容。您还可以使用 successerror,它们根据结果状态代码进行调用。

阅读文档中的所有内容:jQuery.ajax() API

关于jquery - 在 dataFilter 中捕获 http 代码状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13037747/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com