Can someone please show me the basic syntax for loading a page via AJAX just using javascript-- not jquery? load() method?
xmlhttp=new XMLHttpRequest();
Where do I go from here?
Can someone please show me the basic syntax for loading a page via AJAX just using javascript-- not jquery? load() method?
xmlhttp=new XMLHttpRequest();
Where do I go from here?
You will write more lines without jQuery, in jQuery it will done in 2 lines.
Anyway, here is the code
without jQuery
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4)
{
alert(xmlhttp.responseText);
}
}
xmlhttp.open('GET', 'http://www.google.com', true);
xmlhttp.send(null);
if you want to do some POST stuffs
xmlhttp.open("POST",'http://www.google.com', true);
xmlhttp.send();
You also need to do checking for IE
see this link for more understanding - XMLHttpRequest
with jQuety
$.get('http://www.google.com', function(responseText) {
alert(responseText);
});