• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jQuery in Action: Can I use jQuery to go across domains

 
Mike Farnham
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

We had a situation where we wanted to access an application
via https, on another domain.

Does jQuery in Action deal with this possibility?

Thanks,
Mike
 
Ido Green
author
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't do it 'just' with jQuery - BUT here is an easy solution. You can use YQL (web service from yahoo) with jQuery to get just that.
Here is a simple example code that will do the magic for you:


It was posted here:
http://net.tutsplus.com/tutorials/javascript-ajax/quick-tip-cross-domain-ajax-request-with-yql-and-jquery/
and you get there a good short video that explain it as well.

Good luck.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65120
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might also check out jQuery's ability to use JSONP via Ajax.
 
Ido Green
author
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
True.
Here is a simple example for that:

Once the URL includes the string "callback=?" in the URL, the request is treated as JSONP instead.
 
Evguenia Krylova
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do I understand correctly that with the cross-domain requests via AJAX with jQuery it's not possible to provide a handler for error conditions, e.g. when that other server is down.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Evguenia Krylova wrote:Do I understand correctly that with the cross-domain requests via AJAX with jQuery it's not possible to provide a handler for error conditions, e.g. when that other server is down.


JavaScript has a same origin policy. jQuery is JavaScript so it does not have any magical powers as some people think it has. Only way to be 100% sure that the server is up is to use your wonderful server to test the connection. Using a proxy on your end to access the other domain may be your best bet. JSONP is great, but limited.

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic