2016-12-24 18 views
0

我正在使用JQuery版本1.11.3,並且在每次成功響應之後,ajax調用僅轉至.fail方法。我希望成功響應.done函數。我的回答是200 OKAjax調用每次都重定向到.fail方法

$.ajax({ 
    type: "get", 
    url: "/contactslist/"+selectedoption, 
    headers: {'cache-control': 'no-cache'}, 
    json: true, 
}).done(function(data) { 
    console.log("Successs: "+JSON.stringify(data)); 
}) 
.fail(function() { 
    console.log("Failed: "); 
}); 
+0

我找不到jQuery的文檔屬性'json'。 – mm759

+0

將jqXHR傳遞給失敗函數並檢查其值。它可能會給這個問題一些想法。像.fail(function(jqXHR){console.log(jqXHR);} – GeekAb

回答

0

變化JQuery的版本

$(document).ready(function(){ 
    jQuery.ajax({ 
     type: "GET", 
     url: "populateData.htm", 
     dataType:"json", 
     data:"userId=SampleUser", 
     success:function(response){ 
      if (response.redirect) { 
       window.location.href = response.redirect; 
      } 
      else { 
       // Process the expected results... 
      } 
     }, 
    error: function(xhr, textStatus, errorThrown) { 
      alert('Error! Status = ' + xhr.status); 
     } 

    }); 
});