以下是我的 jQuery 脚本代码:
$(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;
}
当我运行上面的代码时,它总是输入 ServiceFailed(xhr) 并警告“错误”。
当我尝试通过浏览器执行上述 url ("http://localhost:9002/SampleServices/Service/REST/Employees") 时,我得到以下 JSON 响应:{"page":1,"records":1," rows":[{"cell":["1","Haris","21-03-1979","HR"],"id":1}],"total":1}
当我运行 jQuery 脚本时,提琴手说:
# 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