如何使用.get使用jquery从外部URL获取内容 [英] How to use .get to get content from external url using jquery

查看:77
本文介绍了如何使用.get使用jquery从外部URL获取内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我试过这段代码从外部网址获取内容,但不幸的是我没有得到。可能是我错了。



请帮帮我,伙计们。



谢谢



Hi,

i have tried this code to get content from external url but unfortunately i'm not getting. May be i'm getting some where wrong.

Please help me, guys.

Thanks

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
//this code is working smooth
    $("button").click(function(){
        $.get("demo_test.asp", function(data, status){
            alert("Data: " + data + "\nStatus: " + status);
        });
    });
});
</script>
</head>
<body>

<button>Send an HTTP GET request to a page and get the result back</button>

</body>
</html>





我尝试过:





What I have tried:

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
//this code is not working
$(document).ready(function(){
    $("button").click(function(){
        $.get("http://www.xxx.com/yy/an/2016Mar24", function(data, status){
            alert("Data: " + data.text() + "\nStatus: " + status);
        });
    });
});
</script>
</head>
<body>

<button>Send an HTTP GET request to a page and get the result back</button>

</body>
</html>

推荐答案

(document).ready(function(){
// this代码工作顺利
(document).ready(function(){ //this code is working smooth


(button)。click(function(){
("button").click(function(){


.get(demo_test.asp,function(data) ,状态){
alert(数据:+数据+\ nStatus:+状态);
});
});
});
< / script>
< / head>
< body>

< button>向网页发送HTTP GET请求并返回结果< / button>

< / body>
< / html>
.get("demo_test.asp", function(data, status){ alert("Data: " + data + "\nStatus: " + status); }); }); }); </script> </head> <body> <button>Send an HTTP GET request to a page and get the result back</button> </body> </html>





我尝试过:





What I have tried:

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
//this code is not working


这篇关于如何使用.get使用jquery从外部URL获取内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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