gpt4 book ai didi

javascript - 从 JQuery 1.4 更改为 1.5.1 并且 getJson 停止工作

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

今天在我工作的网站上,我将 jQuery 的版本从 1.4 更改为 1.5.1,但是这导致依赖于 getJson 函数的函数停止工作,我查看了API 并且由于请求是 getRequest,我认为它是向后兼容的。

代码如下:

function EmailAutoComplete(firstName, lastName, target) {
// Query /AutoComplete/Email?FirstName=&LastName= for an e-mail
// list and populate the select box target with the results.
$.getJSON('@Url.Action("AutoComplete", "Email")', {
FirstName: firstName,
LastName: lastName
}, function(matchingEmails) {
var oldVal = target.val();
target.empty();
if (matchingEmails == null || matchingEmails.length == 0) {
target.append('<option value="">E-mail address not found</option>');
} else {
$.each(matchingEmails, function(key, val) {
var selected = (val == oldVal) ? 'selected="selected"' : '';
target.append('<option value="' + val + '" ' + selected + '>' + val + '</option>');
});

if (matchingEmails.length > 1) {
target.addClass("multipleEmailsAvailable");
} else {
target.removeClass("multipleEmailsAvailable");
}
}
});
}

有没有其他人遇到过这样的问题?

谢谢,亚历克斯。

最佳答案

尝试使用 $.ajax() 并分配 dataType: "text json"

As of jQuery 1.5, jQuery can convert a dataType from what it received in the Content-Type header to what you require. For example, if you want a text response to be treated as XML, use "text xml" for the dataType. You can also make a JSONP request, have it received as text, and interpreted by jQuery as XML: "jsonp text xml." Similarly, a shorthand string such as "jsonp xml" will first attempt to convert from jsonp to xml, and, failing that, convert from jsonp to text, and then from text to xml.

关于javascript - 从 JQuery 1.4 更改为 1.5.1 并且 getJson 停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5294945/

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