gpt4 book ai didi

javascript - 如何从 xmlhttprequest 检索响应? (截图)

转载 作者:行者123 更新时间:2023-11-30 18:30:31 25 4
gpt4 key购买 nike

我有这段自动完成 jqueryUI 的代码:

.autocomplete({
source: function( request, response ) {
var results = $.getJSON( url, {
term: extractLast( request.term )
}, response );
console.log(results);
},...

var 'results' 的 console.log 如下所示: enter image description here

我需要提取 response 或 responseText 字段来测试它是否为空,并弹出一个没有找到匹配项的错误。但是没有任何方法可以检索该字段:

results.response
results.getResponse()
results.getResponseHeader()

这两种方法都行不通。谢谢

两个答案都有效:它正确地返回了我的响应。我可以测试它..但它打破了我的自动完成。我还在研究它。

The third variation, the callback, provides the most flexibility, and can be used to connect any data source to Autocomplete. The callback gets two arguments:

A request object, with a single property called "term", which refersto the value currently in the text input. For example, when the userentered "new yo" in a city field, the Autocomplete term will equal"new yo".

A response callback, which expects a single argument tocontain the data to suggest to the user. This data should be filteredbased on the provided term, and can be in any of the formats describedabove for simple local data (String-Array or Object-Array withlabel/value/both properties). It's important when providing a customsource callback to handle errors during the request. You must alwayscall the response callback even if you encounter an error. Thisensures that the widget always has the correct state.

这是关于回调函数源的 jquery UI 自动完成文档。我不明白为什么新版本不能用

最佳答案

如果你想要你可能想要做的回应

var results = $.getJSON( url, {
term: extractLast( request.term )
}, function(response) {
console.log(response);
});

关于javascript - 如何从 xmlhttprequest 检索响应? (截图),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9770183/

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