簡體   English   中英

如何使用jsonp從跨域獲取響應

[英]How to get response from cross domain using jsonp

我正在跨域上進行AJAX登錄,並且請求已正確發送並從其他域獲得響應,但未調用我的onSuccess函數。 我嘗試在請求中寫onsuccess

sucess : function(){}

但它也沒有被調用。

我的代碼段:

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

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

謝謝

根據文檔,您的請求看起來不錯。 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);
  }
});

因此,您應該添加其他回調,以查看發生了什么問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM