0

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??

3
Contributors
2
Replies
6
Views
6 Years
Discussion Span
Last Post by Palle L
0

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>
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.