简体   繁体   中英

How to get response from cross domain using jsonp

I am working on AJAX login on cross domain and request has been sent correctly and getting response from other domain but my onSuccess function is not getting called. I have tried writing onsuccess inside request like

sucess : function(){}

but it is also not getting called.

My code snippet :

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

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

-Thanx.

Your request looks good, according to the documentation. From README.md

Handling Failures

Since there is no way to inspect what happens after we make a request with the JSONP technique, we're stuck having to make informed guesses about what's going on.

This example makes a request to an invalid URL. Since the callback is not invoked within the default timeout period (10 seconds) the request is "cancelled" and the onFailure callback is invoked if specified. The Ajax.JSONResponse will have the status of 504 and statusText of "Gateway Timeout".

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);
  }
});

So, you should add the additional callbacks, to see what's going wrong.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM