*
The moose likes HTML, CSS and JavaScript and the fly likes jQuery in Action: Can I use jQuery to go across domains Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "jQuery in Action: Can I use jQuery to go across domains" Watch "jQuery in Action: Can I use jQuery to go across domains" New topic
Author

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

Mike Farnham
Ranch Hand

Joined: Sep 25, 2001
Posts: 76
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

Joined: Jul 27, 2010
Posts: 25
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

Joined: Jan 10, 2002
Posts: 60780
    
  65

You might also check out jQuery's ability to use JSONP via Ajax.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ido Green
author
Greenhorn

Joined: Jul 27, 2010
Posts: 25
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

Joined: Oct 18, 2002
Posts: 3
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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
 
jQuery in Action, 2nd edition
 
subject: jQuery in Action: Can I use jQuery to go across domains
 
Similar Threads
Bumper Sticker item requests
WA #1.....word association
compare with prototype
Which UI Toolkit and Why
* Welcome Bear Bibeault