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.
Try Using
$.ajax()instead and assigndataType: "text json"