【问题标题】:Json response gives undefined error in chrome but works in IEJson 响应在 chrome 中给出未定义的错误,但在 IE 中有效
【发布时间】: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


【解决方案1】:

对跨域使用 dataType="jsonp"。您可能还需要设置“crossDomain: true”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-08
    • 2019-02-25
    • 2012-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-25
    相关资源
    最近更新 更多