I created an aspx file that act as JSON result.
Response.Clear()
Response.ContentType = "application/json; charset=utf-8"
I have another page (another domain) that read that JSON. But I got syntax error: invalid label when calling the JSON value.
$.getJSON( "http://a.com/json.aspx?format=json&jsoncallback=?" , function(data) {
alert(data);
});
}
You need the server to output JSONP, not JSON. JSONP is different. JSONP is used when the server is on a different domain then the client.
JSONP is actually just a JavaScript file, so it should be served with
Content-type: text/javascript. When serving JSONP, you should wrap the JSON in the value ofjsoncallback.So, your web server should output something similar to:
Where
jQuery12345is the value of thejsoncallbackparameter in the query string, which will be automatically set by jQuery.jQuery will automatically replace the
?with a value.More info on JSONP: http://en.wikipedia.org/wiki/JSONP