gpt4 book ai didi

jquery - jQuery jsonp ajax 请求的查询字符串中的下划线代表什么?

转载 作者:行者123 更新时间:2023-12-03 21:54:16 25 4
gpt4 key购买 nike

当我查看来自 jsonp 请求的查询字符串(下面的客户端代码)时,有 2 个对象,一个需要在响应中使用的“回调”字符串(因此客户端代码定向到成功处理程序)和键为 _...这个下划线是做什么用的?我在任何文档中都找不到对此的任何引用,它似乎是某种类型的数字。

我认为它可能用于定向到错误处理程序(无论是在其打开时,与回调结合使用,还是替换回调字符串中下划线后面的数字),但似乎并非如此。

url = 'http://localhost:11767/Handlers/MyHandler.ashx';

...

$.ajax({
url: url,
dataType: "jsonp",
error: function (jqXHR, textStatus, errorThrown) {
//...
},
success : function(d) {
//...
}
});

    $.getJSON(url + "?callback=?", function(d) {
}).success(function(d) {
//...
}).error(function(jqXHR, textStatus, errorThrown) {
//...
}).complete(function(d) {
//...
});

旁注,以防有人阅读此内容:因为这是一个 jsonp 请求,只有在客户端发生异常时才会出现错误,例如响应格式存在超时或问题(即不使用回调),为了克服这个问题,我总是记录并吞下处理程序中的异常,但给出一个标准响应对象(所有响应都是由它组成的)具有异常状态属性和消息属性。

最佳答案

您引用的数字是请求的日期时间戳。获取号码并使用浏览器的 JavaScript 控制台并输入:alert(new Date(/*在此处插入号码*/))

您将收到一 strip 有日期/时间的提醒。

编辑:

这是来自 jQuery.ajax 的片段关于 ajax 请求的文档:

cache
Default: true, false for dataType 'script' and 'jsonp'
If set to false, it will force requested pages not to be cached by the browser. Setting cache to false also appends a query string parameter, "_=[TIMESTAMP]", to the URL.

关于jquery - jQuery jsonp ajax 请求的查询字符串中的下划线代表什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12709686/

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