Json响应在chrome中给出了未定义的错误,但在IE中有效
我不熟悉ajax和跨域,在这里我一无所知,我一直在努力研究上面提到的标题,它一直指向跨域错误,有人可以帮助我如何修复代码,以遵守这些跨域 这是我的密码:Json响应在chrome中给出了未定义的错误,但在IE中有效,json,jquery,cross-domain,undefined,Json,Jquery,Cross Domain,Undefined,我不熟悉ajax和跨域,在这里我一无所知,我一直在努力研究上面提到的标题,它一直指向跨域错误,有人可以帮助我如何修复代码,以遵守这些跨域 这是我的密码: function GetEmployeeInformation() { $.ajax({ type: "GET", url: "http://localhost:8080/SampleEmpService/Employees/" + $("#txtEmpno").val
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 />");
}
});
}
函数GetEmployeeInformation(){
$.ajax({
键入:“获取”,
url:“http://localhost:8080/SampleEmpService/Employees/“+$(“#txtEmpno”).val(),
contentType:“应用程序/json;字符集=utf-8”,
cache:false,
数据类型:“json”,
错误:函数(xhr、ajaxOptions、thrownError){
警报(xhr.状态);
警报(xhr.statusText);
警报(thrownError)
},
成功:功能(响应){
$(“#divEmployeeInfo”).html(“”);
$(“#divEmployeeInfo”).append(“Id:”).append(response.Empno+“”); $(“#divEmployeeInfo”).append(“名称:”).append(response.Ename+“
”); $(“#divEmployeeInfo”).append(“工资:”).append(response.Sal+“
”); $(“#divEmployeeInfo”).append(“Deptno:”).append(response.Deptno+”
); } }); }
它在IE中工作正常,但在chrome中会出现错误和未定义的错误。跨域使用dataType=“jsonp”。您可能还需要设置“crossDomain:true”。get请求中没有任何内容,请尝试删除
contentType