我是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中会出现未定义的错误。
发布于 2012-08-27 03:04:39
跨域使用dataType="jsonp“。您可能还需要设置"crossDomain: true“。
https://stackoverflow.com/questions/12132860
复制相似问题