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" 

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

    var xmlHttp = createXmlHttpRequestObject();
    function createXmlHttpRequestObject() { var xmlHttp;
    if(window.ActiveXObject)  {
    try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    catch (e) {
    xmlHttp = false;
    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( 
    xmlHttp.open("GET", "quickstart.php?name=" + name, true);  
    xmlHttp.onreadystatechange = handleServerResponse;
    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: " + 
    3) quickstart.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!';
    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.

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 :