I am fetching Google in a gadget using this code:
<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>
I wonder how can I do the same thing using $ajax?
I looked at different examples but I don’t know how they gonna fit in this situation. Or if you can post some nice $ajax tutorials please.
When I change it to this, it doesn’t work:
<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>
Nothing comes up on the page.
Here’s a jQuery version of the code:
For more details and settings, read the
jQuery.ajax()documentation