繁体   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