从 JQuery 1.4 更改为 1.5.1 并且 getJson 停止工作
今天,在我正在开发的一个网站上,我将 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");
}
}
});
}
还有其他人遇到过这样的问题吗?
谢谢, 亚历克斯.
Today on a website I was working on I changed the version of jQuery from 1.4 to 1.5.1, however this caused a function which relies on the getJson
function to stop working, I have looked at the API and as the request is a getRequest I assumed it was backwards compatible.
Here is the code:
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");
}
}
});
}
Has anyone else had an issue like this?
Thanks,
Alex.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用
$.ajax()
代替并分配dataType: "text json"
Try Using
$.ajax()
instead and assigndataType: "text json"
我遇到了同样的问题。
结果我的 json 文件无效。
修复我的 json 文件后,getJson 再次变得魅力十足。
I ran into this very same issue.
Turns out my json file was not valid.
After fixing my json file getJson worked like a charm again.