2014-04-08 166 views
0

我有一個函數調用成功時的另一個函數。我已經使用警報,你可以看到它,它會提醒「2」。函數不會調用其他函數

在F12按下有一個500服務器錯誤,但我也可以看到,我的web服務確實工作,因爲我看到它在XML中正確提取所有數據。我的data: param或查詢字符串也會得到正確的值。

的JavaScript:

function ContactView() 
{ 
    alert("1") 
    var txtSearchbox = $("#searchTextField").val(); 
$.ajax({ 
     type: "GET", 
     data: param = "searchField="+txtSearchbox+"&office="+localStorage.getItem("office")+"&person="+localStorage.getItem("person")+"&user="+localStorage.getItem("user")+"&organization="+localStorage.getItem("organization"), 
     contentType: "application/json; charset=utf-8", 
     url: "http://msw-wsdl.company.net/mobile.asmx/ContactGet", 
     dataType: "json", 
     success: successContact, 
     failure: function (msg) { 
      console.log(msg); 
     } 
    }); 
    alert("2") /*this is the last alert that pop's up, nothing further*/ 
} 
/*wsdl call succeed*/ 
function successContact(data) { 
    alert("3") 
    $("#lstView_contacts").kendoMobileListView({ 
     dataSource: JSON.parse(data.d), 
     template: $("#lstView_contact_Template").html(), 
     endlessScroll: true, 
     scrollThreshold: 8 
    }); 
    window.location = "#contactsview"; 
} 

爲什麼成功回調successContact不叫 - 任何想法?

+0

沒有'失敗'選項,所以**當**由於相同的起始策略而失敗時,您在控制檯中沒有收到「解析錯誤」消息,請將其更改爲「error」。 – adeneo

+0

@adeneo:我收到了一個更好的錯誤 - 「{」readyState「:4,」responseText「:」{\「Message \」:\「處理請求時發生錯誤。」,「StackTrace \」: \「\」,\「ExceptionType \」:\「\」}「,」狀態「:500,」statusText「:」內部服務器錯誤「} – user3458266

+0

直到500錯誤得到解決,您才能獲得成功。檢查您發送到服務器的數據,確保它的格式正確,以便在服務器端正確使用,而不是生成錯誤。 –

回答

2

函數successContact只會在成功時纔會被調用,而錯誤500意味着它不成功。 error方法將被調用,而不是你的情況下定義。

+0

錯誤的方法是在我的代碼中沒有粘貼它。 – user3458266

+0

如果您正在使用'跨域請求'或'JSONP',那麼'error'方法將不會被調用。你嘗試過jQuery ajax的'done','fail'和'always'方法嗎? –