I am trying .ajax to hit a URL which returns a list of object, I am using jacksonJsonView in spring to it returns json in browser. But when I try this code it never goes into the success, but the error alert shows the textstatus to be 'parseerror'. the alert looks like this: 'status=parsererror,error=jQuery15109695890768120119_1357924928198 was not called'
$(function() {
$("#tags").autocomplete({
source: function( request, response ) {
$.ajax({
url: 'http://localhost:8181/jquery/api/states/regex?stateName='+request.term,
method: 'GET',
dataType: 'jsonp',
success: function(json) {
alert("test");
},
error: function(httpRequest, textStatus, errorThrown) {
alert("status=" + textStatus + ",error=" + errorThrown);
}
});
}
})
The API returns some thing like this:
[
{
"id": 12,
"stateName": "Vermont",
"intPtLon": -72.673354,
"intPtLat": 44.0605475,
"stUsps": "VT"
},
{
"id": 20,
"stateName": "Virginia",
"intPtLon": -78.6681938,
"intPtLat": 37.5222512,
"stUsps": "VA"
}
]
Adding the following line fixed the issue, it works fine in IE bit not so much in firefox
dataType: 'jsonp',todataType: 'json',will be completely enough.