0

Hello all,
I am just learning AJAX because I find it interesting but my first example does not work the way I planned it.
Here is the code:
This is my HTML file named ajax.html

<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <meta name="author" content="" />

    <title>Untitled 3</title>
    <script type="text/javascript" language="javascript" src="jscript.js">

</script>

</head>

<body>

<h1> My AJAX example</h1>
<button onclick="callAjax()" >Ajax</button>
<div id="d" name="d"></div>
</body>
</html>

// This is my javascript file named jscript.js

function callAjax(){
    alert("ajax method called");
    if (window.active)
var xhr=new XMLHttpRequest();
xhr.onreadystatechange=function(){
    if(xhr.readyState==4 && xhr.status==200){
    document.getElementById("d").innerHTML=xhr.responseText;
}
};
xhr.open('GET','ajax.php',true);
xhr.send();

}

// This is my server side PHP code named ajax.php
<?php
echo "Welcome to AJAX world";

?>

Edited by mike_2000_17: Fixed formatting

3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by SolidSolutions
0

Thank you all for showing concern. My codes later worked after adjusting some things.

0

Great!

- please upvote anyone who helped.
- please mark thread as solved.
- please post specifics about solution if possible.

This question has already been answered. 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.