开发者

Simple cross domain html request with jquery? Trying to use plug-in

I'm trying to perform a simple html request using jquery with the code below.

$.get('http://externalsite.com/status.html', function(data) {

if (data == 1) {
//do something
}

else {
//do something else
}

});

I'm using the cross domain request开发者_如何学Python plugin found at http://james.padolsey.com/javascript/cross-domain-requests-with-jquery/ and I added the .js script to my html file, but what's next? The example uses a #container and a load from google, but I'm lost as to what I do for an html request. It says it works for any .get request, I just don't know how to do it. Thanks for your help.


You can do whatever you want. Read the jQuery docs for .load() and .get() :

This example puts the contents of http://google.com in the HTML element with id="container":

$('#container').load('http://google.com');

This does the same thing but with your example site:

$('#container').load('http://externalsite.com/status.html');

This also does the same thing as above:

$.get('http://externalsite.com/status.html', function(data) {    
    $('#container').html(data);
});


i am not sure what your problem exactly is, can you for example wrap this code into the function and simple invoke it ? :) like

function makeAjaxCall(url){
 $.get(url, function (...)
}

makeAjaxCall('http://google.com');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜