1

I am making a dashcode webapp and all I want is a single digit, a 1 or 0 returned from an external server so if there is an easier way to do this please let me know. I am using the plug in found at http://james.padolsey.com/javascript/cross-domain-requests-with-jquery/ to try to make a cross domain request, but everything I am trying isn't working.

When I run this code

$.ajax({
  url: "status.html",
  context: document.body,
  success: function(data){
    alert("working" + data);
  }
});

everything works perfectly and an alert with the text "working1" is displayed, but when I run this code

$.ajax({
  url: "http://externalsite.com/status.html",
  context: document.body,
  success: function(data){
    alert("working" + data);
  }
});

nothing happens. Can anyone help? This is just what I am trying now, I've also tried a .get request and the returned data was "objectObject" I also tried a php proxy without any luck. I'm just asking for a simple solution to return a SINGLE number from an external server.

davis
  • 1,911
  • 6
  • 26
  • 50

2 Answers2

2

If you can control other server output, put header:

Access-Control-Allow-Origin: *

in http response, and load with ajax without plugins or using YQL

https://developer.mozilla.org/en/HTTP_access_control

Jacek Kaniuk
  • 5,229
  • 26
  • 28
  • This is not supported in all browsers http://en.wikipedia.org/wiki/XMLHttpRequest#Cross-domain_requests (but frankly JSONP may not be, either) – Dan Esparza Aug 05 '11 at 21:53
  • @Jacek_FH I read that this is supported by safari, to enable it do I just put Access-Control-Allow-Origin: * in the header of my status.html file? – davis Aug 05 '11 at 23:51
  • in HTTP header, not HTML - for example with PHP its: header('Access-Control-Allow-Origin: *'); – Jacek Kaniuk Aug 06 '11 at 00:11
  • This definitely is the answer I'm looking for, I just can't find a web host who allows me to add this. – davis Aug 11 '11 at 00:51
  • any with php -> header('Access-Control-Allow-Origin: *'); – Jacek Kaniuk Aug 11 '11 at 00:58
0

It looks like the plugin is making a JSONP request via YQL (see line 18 here).

If you load up Firebug or the developer tools in Chrome, do you see the JSONP request being made?

Dan Esparza
  • 28,047
  • 29
  • 99
  • 127