【发布时间】:2012-08-26 18:41:55
【问题描述】:
我是 ajax 和跨域新手,我在这里一头雾水,我一直在尝试研究上述标题,但它一直指向跨域错误,有人可以帮我解决如何修复代码坚持这些跨域。
这是我的代码:
function GetEmployeeInformation() {
$.ajax({
type: "GET",
url: "http://localhost:8080/SampleEmpService/Employees/" + $("#txtEmpno").val(),
contentType: "application/json; charset=utf-8",
cache:false,
dataType:"json",
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(xhr.statusText);
alert(thrownError)
},
success: function (response) {
$("#divEmployeeInfo").html("");
$("#divEmployeeInfo").append("Id: ").append(response.Empno + "<br />");
$("#divEmployeeInfo").append("Name: ").append(response.Ename + "<br />");
$("#divEmployeeInfo").append("Salary: ").append(response.Sal + "<br />");
$("#divEmployeeInfo").append("Deptno: ").append(response.Deptno + "<br />");
}
});
}
它在 IE 中运行良好,但在 chrome 中出现未定义的错误。
【问题讨论】:
-
get请求中没有任何内容,请尝试删除
contentType
标签: json jquery cross-domain undefined