Using IE8, jQuery 1.6.1.min.js.
The JSON that comes from the REST service seems to be valid (atleast when I validate it on jsonlint.com)
{
"requestId":"1624517264",
"acknowledge":1,
"errorCode":0,
"totalResultCount":2,
"results":[
{"EmployeeCode":"007","EmployeeUno":7,"EmployeeName":"Bond, James","Location":"Unknown","Login":"JBOND"},
{"EmployeeCode":"008","EmployeeUno":8,"EmployeeName":"Bar, Foo","Location":"NYC","Login":"FBAR"}
]}
jQuery:
$.getJSON(urlToSvc + "&callback=?", function (data) {
// can't get to here
});
I get a javascript error Expected ';'. What am I doing wrong?
If that's exactly the response from urlToSvc, then it looks like you're making a JSONP request but urlToSvc is returning plain JSON.
If you use a tool like Firebug to inspect the request that $.getJSON()
makes, you should find that it's replacing callback=?
with something like callback=jQuery152012865984649397433_1306892572812
. That means jQuery expects the JSON to be returned as a parameter to a function call to jQuery152012865984649397433_1306892572812()
. That's how it wires up your callback function behind the scenes.
In that case, the response should look something like this (though the exact function name will change on every request, specified by the callback
querystring parameter):
jQuery152012865984649397433_1306892572812('{"requestId":"1624517264","acknowledge":1,"errorCode":0,"totalResultCount":2,"results":[{"EmployeeCode":"007","EmployeeUno":7,"EmployeeName":"Bond, James","Location":"Unknown","Login":"JBOND"},{"EmployeeCode":"008","EmployeeUno":8,"EmployeeName":"Bar, Foo","Location":"NYC","Login":"FBAR"}]}')