Hii,
I am trying to get a content of a php page(Dynamic) with the help of Ajax by sending Get request to the server page.Like the script should fetch the content of server page (Can be changeable with time )into a certain div tag that i will define.


I dont wanna use prototype.js to make the script little bit faster.
How to do that??

see the code below

<!DOCTYPE html>
<html>
<head>
<title>Ajax Request</title>
<script type="text/javascript">
var xhr = false;
if (window.ActiveXObject){
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
else {
xhr = new XMLHttpRequest();
}
xhr.open("GET","yourpage.php",true); // Insert a reference of the php page you wanna get instead of yourpage.php
xhr.send(null);
xhr.onreadystatechange = function () {
if (xhr.redayState == 4 && xhr.status = 200)
{
document.getElementById('ajax_response').innerHTML = xhr.responseText;
}
else {
alert ('Request Failed' + xhr.status);
}
}


</script>
</head>
<body>
<div id="ajax_response"> <!-- Inside This Div the PHP Page will display -->


</div>

</body>
</html>

Change:

if (xhr.redayState == 4 && xhr.status = 200)

to:

if (xhr.readyState == 4 && xhr.status == 200)

Note that readyState was wrong and a = was missing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.