Ask questions and get good answers on jQuery

I'm trying to load some content from a different domain url into a jquery.mb.containerPlus via ajax without results... Is there a way to get this content using ajax?

asked Nov 05 '09 at 19:05

Ruby's gravatar image

Ruby
2112

edited Nov 07 '09 at 08:28

Pietro%20Polsinelli's gravatar image

Pietro Polsinelli ♦♦
407


Actually, the only way to get content from a different domain is by using a Json call. Beginning with version 1.2, jQuery has had native support for JSONP calls. You can load JSON data located on another domain if you specify a JSONP callback, which can be done using the following syntax: url?callback=?.

jQuery.getJSON(url+"&callback=?", function(data) {
    alert("Symbol: " + data.symbol + ", Price: " + data.price);
});

To do this, jQuery attaches a global function to the window object that is called when the script is inserted. This function is removed upon completion. Furthermore, jQuery has an optimization for non-cross-domain calls as well. If the request is being made to the same domain, then jQuery turns it into an ordinary Ajax request.

Note that there is no error handling for JSONP calls. If the dynamic script insertion works, you get called; if not, nothing happens. It just fails silently.

answered Nov 05 '09 at 19:45

Matteo%20Bicocchi's gravatar image

Matteo Bicocchi ♦♦
1776129

Your answer
toggle preview

jQuery main site - Matteo Bicocchi