I have a WCF Service that return JSON format Data. When i use a Web Browser i can easily see the result but when using Jquery getJSON i cannot get it to work. i can see in fiddler that it is returning the data but in firebug it shows with red font and empty response.
here is my WCF service
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "GetUrl/{iType}")]
String GetUrl(string iType);
public String GetUrl(string iType)
{
return strurl;
}
MY JSON call looks like this
$.getJSON("http://localhost/UrlSvc/UrlService.svc/GetUrl/1",
function (data) {
console.log("Data JSOn Got");
$.each(data.items, function (i, item) {
console.log("Data Received");
});
});
when i just put that url in browser i get this below in response as expected
{"GetChartUrlResult":"ulr_fdba9bc2-7ff7-467f-a6e0-6f4d234169d2.png"}
BUT getJSOn returns Empty Response as seen in Firebug with Red font on the url Itself.
this is a cross domain call and i have enabled cross domain it WCF
If the call is cross domain, you have to use jsonp. You can use it with
$.getJSONby adding?callback=?to the URL (depending on the server-side API). Make sure that your API does support emitting the callback appropriately.Documentation here: http://api.jquery.com/jQuery.getJSON/