简单的跨域html请求与jquery?尝试使用插件 [英] Simple cross domain html request with jquery? Trying to use plug-in

查看:152
本文介绍了简单的跨域html请求与jquery?尝试使用插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用下面的代码使用jquery执行一个简单的html请求。

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
}

});

我使用的是 http://james.padolsey.com/javascript/cross-domain-requests-with-jquery/
和我添加.js脚本到我的html文件,但下一步是什么?该示例使用#container和来自google的加载,但我失去了我为一个html请求做的。它说它适用于任何.get请求,我只是不知道如何做。感谢您的帮助。

I'm using the cross domain request 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.

推荐答案

你可以做任何你想要的。阅读 .load()。get()

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

id =container的HTML元素中输入c $ c> http://google.com :

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');

这也和上面一样:

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

这篇关于简单的跨域html请求与jquery?尝试使用插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆