AJAX Program Problem on 000Webhost.com

Well i am trying to Test the AJAX code and running the sample Example from this book :

  • AJAX and PHP By: Audra Hendrix; Bogdan Brinzarea; Cristian Darie


    Now there are Three Files :



    1) Index.html
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>AJAX with PHP, 2nd Edition: Quickstart</title>
    <script type="text/javascript" src="quickstart.js"></script>
    </head>
    <body onload='process()'>
    Server wants to know your name: <input type="text" id="myName" />
    <div id="divMessage" />
    </body>
    </html>
    2) quickstart.js

    var xmlHttp = createXmlHttpRequestObject();
    function createXmlHttpRequestObject() { var xmlHttp;
    if(window.ActiveXObject)  {
    try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) {
    xmlHttp = false;
    }
    }
    else
    {
    try {
    xmlHttp = new XMLHttpRequest();
    }
    catch (e) {
    xmlHttp = false;
    }
    }
    if (!xmlHttp)
    alert("Error creating the XMLHttpRequest object.");
    else return xmlHttp;
    }
    function process(){
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)  {
    name = encodeURIComponent( 
    document.getElementById("myName").value);
    xmlHttp.open("GET", "quickstart.php?name=" + name, true);  
    xmlHttp.onreadystatechange = handleServerResponse;
    xmlHttp.send(null);
    }
    else
    setTimeout('process()', 1000);
    }
    function handleServerResponse() {
    if (xmlHttp.readyState == 4)   {
    if (xmlHttp.status == 200)    {
    xmlResponse = xmlHttp.responseXML;
    xmlDocumentElement = xmlResponse.documentElement;
    helloMessage = xmlDocumentElement.firstChild.data;
    document.getElementById("divMessage").innerHTML = '<i>' + helloMessage + '</i>';
    setTimeout('process()', 1000);
    } else     {
    alert("There was a problem accessing the server: " + 
    xmlHttp.statusText);
    }
    }
    }
    3) quickstart.php


    <?php
    header('Content-Type: text/xml');
    echo '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
    echo '<response>';
    $name = $_GET['name'];
    $userNames = array('YODA', 'AUDRA', 'BOGDAN', 'CRISTIAN');
    if (in_array(strtoupper($name), $userNames))
    echo 'Hello, master ' . htmlentities($name) . '!';
    else if (trim($name) == '')
    echo 'Stranger, please tell me your name!';
    else
    echo htmlentities($name) . ', I don\'t know you!';
    echo '</response>';?>
    When i am running the above index.html on my localhost using Wamp Server it is showing me the Perfect output and its also working Perfectly with output like this :



    But the same code is showing me the problem when i upload it into my Site: 000Webhost.com

    I tried on 3 Different Browsers:

    1) Google Chrome showing me No Error but the code is not running either.

    2) FireFox is showing this error as give in Screenshot:



    3) And IE8 is showing this:



    I have tried to find the Solution from Internet but nothing was helpful. So if anyone can  Provide the Solution , i shall be thankful. In the mean time i am also trying to Figure out the solution and i'll post it here if i get it earlier.
    Thanks



1 comment:

PC said...

Will I got some help from Lawrence from StackOverflow and the His code worked , thought i didnt get any solution for above code.
You can check his answer at :
http://stackoverflow.com/questions/10671000/ajax-program-not-running-on-webstie-but-working-fine-on-local-wamp-server