Ajax请求不起作用?

时间:2015-12-29 10:51:49

标签: javascript jquery html ajax

当我尝试发布JSON时,我无法看到任何请求,而且我的本地服务器甚至没有收到这些电话。

这是我的ajax部分

function callserver(){
  var markers = {"regDate" : 1451330123000, "specialities" : " ", "isActive" : true, "mobileNo" : "876876","id" : 0, "completed" : false,"mcname" : "", "password" : "hgh","role" : "SuperAdmin,Consultant","logins" : [],"email" : "testtestets@test.com","name" : "regcg","organization" : "hghjg"};    
  alert(markers);    
  $.ajax({
    type: "POST",
    data:markers,
    headers: {
      'Accept':'application/vnd.company.productname-v1+json',
      'X-PD-Authentication':'42</B7Tg8o5C7`7<7Ar0?]pJs`@Noplt>I1m>QYQn[v=osDl:unWyx`SYqBK@0?w',
      'Content-Type':'application/json'
    },
    dataType: "json",
    url: "http://x.x.x.x:9001/users",
    success: function(data) {
      alert("success");
    },
    error: function () {
      alert("failure");
    }
  });

}

直到alert(markers);正在运作,但之后

我没有得到&#34;成功&#34;或者&#34;失败&#34;警报。 控制台截图

enter image description here

enter image description here

请帮帮我

1 个答案:

答案 0 :(得分:2)

正如您not ready to show the full HTML,看起来您正在使用另一个带有jQuery的库,因为jQuery works。所以请将所有$更改为jQuery

function callserver(){
  var markers = {"regDate" : 1451330123000, "specialities" : " ", "isActive" : true, "mobileNo" : "876876","id" : 0, "completed" : false,"mcname" : "", "password" : "hgh","role" : "SuperAdmin,Consultant","logins" : [],"email" : "testtestets@test.com","name" : "regcg","organization" : "hghjg"};    
  alert(markers);
  // Change here
  jQuery.ajax({
    type: "POST",
    data:markers,
    headers: {
      'Accept':'application/vnd.company.productname-v1+json',
      'X-PD-Authentication':'42</B7Tg8o5C7`7<7Ar0?]pJs`@Noplt>I1m>QYQn[v=osDl:unWyx`SYqBK@0?w',
      'Content-Type':'application/json'
    },
    dataType: "json",
    url: "http://x.x.x.x:9001/users",
    success: function(data) {
      alert("success");
    },
    error: function () {
      alert("failure");
    }
  });
}