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

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




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

// This is my javascript file named jscript.js

function callAjax(){
    alert("ajax method called");
    if (window.active)
var xhr=new XMLHttpRequest();
    if(xhr.readyState==4 && xhr.status==200){


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


You should provide a full URL, not just ajax.php in the xhr.open()

Next time, please use code tags.

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


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