0

I'm building both an application and the server (unfortunately on different domains)

On the application I have:

$.ajax({
  url: BASE_URL + "api/create",
  type: "get",
  async: false, // why do I need this
  dataType: "jsonp",
  data: {
    "auth_token": "cBQHASwKszsW4e75unK6"
  }, 
  error: function(error) {
    alert(JSON.stringify(error));
  },
  success: function(data) {
    alert(data);
  }
});

I know that the server is returning (when I go to it in a browser):

jQuery1910041686943266540766_1365730282085({"error":"User does not exist","status":400})

(which is correct data)

However, the ajax request fails and is listed as status "failed" and type "pending"

I'm not sure what's going on here


I have also tried:

 $.getJSON(BASE_URL + "api/create?auth_token=cBQHASwKszsW4e75unK6&callback=?", function(data) {
   alert(JSON.stringify(data));
 });

which also failed

Shazam
  • 689
  • 2
  • 9
  • 17
  • 1
    You got `jQuery1910041686...` without specifying callback function var? What address you got in `Net` tab in `Firebug`? – Narek Apr 12 '13 at 07:30
  • `async` can't be false for jsonp as far as I know. Not saying it's related to your issue, but a cross-domain jsonp request adds a script tag and that is async. – Paul Grime Apr 12 '13 at 07:32
  • localhost:3000/api/create?callback=jQuery19101939692951273173_1365751304024&auth_token=cBQHASwKszsW4e75unK - to answer the first question, the callback argument is apparently added by jquery – Shazam Apr 12 '13 at 07:33
  • I set async to true and it still fails. also added a 10 second wait and it still fails – Shazam Apr 12 '13 at 07:37
  • Sorry, I meant I tried true – Shazam Apr 12 '13 at 07:39
  • Hanging like this, I'd guess jQuery is the one cancelling the request.. perhaps origin control issue as in http://stackoverflow.com/a/14915325/1613589 ? You server obviously replies correctly to jsonp requests, so it's something the $.ajax did not like (that's why you don't see the actual response form the server in the Network monitor console in the browser). Never tried it with jsonp but perhaps http://api.jquery.com/ajaxComplete/ global event (or even preFilter) can hopefully help you see the exact response.. Still, nothing in error console? – Damyan Petev Apr 12 '13 at 11:29
  • 1. I have added the headers in the server 2. ajaxComplete does not fire 3. here are all ajax requests sent by my browser (from preFilter) http://pastebin.com/W8tSMeTg – Shazam Apr 12 '13 at 18:29

1 Answers1

-1

For this you need to crate a proxy page. Ex : proxy.php

calling the request directly call proxy.php via ajax

Lets know it works for u.

Steps : 1. create a new page proxy.php 2. Use CURL or File_get_contents to fetch the data from the external URL. 3. Call the proxy.php via ajax in place of cross domain URL.

deep2mail
  • 1
  • 3