2013-02-13 71 views
0

我正在處理跨域的AJAX登錄,並且請求已被正確發送並獲得來自其他域的響應,但是我的onSuccess函數未被調用。 我試圖寫的onSuccess內在要求像如何使用jsonp獲得來自跨域的響應

sucess : function(){} 

,但它也沒有得到調用。

我的代碼片段:

new Ajax.JSONRequest(this.preCheckUrl, { 
    callbackParamName: "jsoncallback", 
    parameters: { 
    userEmail: this.userEmail, userPassword: this.userPassword, format: 'json' 
    }, 

    onSuccess:function(response) { 
     alert('hello'); 
    } }); 

-Thanx。

回答

0

根據文檔,您的要求看起來不錯。 從README.md

處理故障

既然沒有辦法來檢查,我們做與JSONP技術的請求之後會發生什麼,我們堅持必須做出什麼事情知情的猜測。

本示例向無效URL發出請求。由於在默認的超時期限(10秒)內沒有調用回調,所以請求被「取消」,並且如果指定,則調用onFailure回調。 Ajax.JSONResponse將具有狀態504和statusText「網關超時」。

new Ajax.JSONRequest('http://api.flickr.com/services/feeds/asdfasdfasdfasdfasdfsdf', { 
    callbackParamName: "jsoncallback", 
    parameters: { 
    tags: 'cat', tagmode: 'any', format: 'json' 
    }, 
    onCreate: function(response) { 
    console.log("2: create", response, response.responseJSON); 
    }, 
    onSuccess: function(response) { 
    console.log("2: success", response, response.responseJSON); 
    }, 
    onFailure: function(response) { 
    console.log("2: fail", response, response.responseJSON); 
    }, 
    onComplete: function(response) { 
    console.log("2: complete", response, response.responseJSON); 
    } 
}); 

所以,你應該添加額外的回調,看看有什麼地方出了錯。