Following is my code from jQuery script:
$(document).ready(function () {
$.ajax({
cache: false,
type: "GET",
async: true,
dataType: "json",
url: "http://localhost:9002/SampleServices/Service/REST/Employees",
processdata: false,
error: ServiceFailed,
success: function () { alert("succeeded"); }
});
});
function ServiceFailed(result) {
alert('Service call failed: ' + result.status + '' + result.statusText);
Type = null;
Url = null;
Data = null;
ContentType = null;
DataType = null;
ProcessData = null;
}
function ServiceFailed(xhr) {
alert("error");
alert(xhr.responseText);
if (xhr.responseText) {
var err = xhr.responseText;
if (err)
error(err);
else
error({ Message: "Unknown server error." })
}
return;
}
When I run the above code it always enters ServiceFailed(xhr) and alerts “error”.
When I try to execute the above url (“http://localhost:9002/SampleServices/Service/REST/Employees”) through the browser I get following JSON response:
{“page”:1,”records”:1,”rows”:[{“cell”:[“1″,”Haris”,”21-03-1979″,”HR”],”id”:1}],”total”:1}
Fiddler says following when I run the jQuery script:
# Result Protocol Host URL Body Caching Content-Type Process Comments Custom
1 200 HTTP localhost:9002 /SampleServices/Service/REST/Employees?_=1340833203960 89 application/json; charset=utf-8 chrome:1448
carlosfigueira nailed it.
This was a cross domain request hence i needed to add crossdomain support in App.config file for my WCF service