Muh*_*aja -5 javascript xml jquery xmlhttprequest
我使用以下代码在小工具中获取Google:
<html>
<head>
<title>Browser</title>
</head>
<body onload= "getListCollection()" style="width:900px; height:900px;" >
<div id="listAttributes" style="width:400px; height:400px;" ></div>
<script>
function getListCollection() {
var url = "https://www.google.co.uk"
xmlhttp = new XMLHttpRequest();
xmlhttp.open('GET',url,true, 'user', 'password');
xmlhttp.onreadystatechange = function()
{
if(xmlhttp.readyState == 4);
{
document.getElementById("listAttributes").innerHTML = xmlhttp.responseText
}
}
xmlhttp.send(null);
}
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我想知道如何使用$ ajax做同样的事情?
我看了不同的例子,但我不知道他们将如何适应这种情况.或者,如果你可以发布一些不错的$ ajax教程.
当我将其更改为此时,它不起作用:
<html>
<head>
<title>Browser</title>
</head>
<body onload= "getListCollection()" style="width:900px; height:900px;" >
<div id="listAttributes" style="width:400px; height:400px;" ></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js">
$.ajax({
url : 'https://www.google.co.uk',
type : 'GET',
success : function(data){
$('#listAttributes').html(data);
}
});
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
页面上没有任何内容.
这是代码的jQuery版本:
$.ajax({
url : 'https://www.google.co.uk', //cross-domain? this won't work
username : 'user',
password : 'password',
type : 'GET', //default is GET, but i put it here to clarify
success : function(data){
$('#listAttributes').html(data);
}
});
Run Code Online (Sandbox Code Playgroud)
有关更多详细信息和设置,请阅读jQuery.ajax()文档
| 归档时间: |
|
| 查看次数: |
2433 次 |
| 最近记录: |