How to run Ajax on Local Computer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mfaisalwarraich
    New Member
    • Oct 2007
    • 194

    How to run Ajax on Local Computer

    Hi All,

    I am new in the Ajax. I want to know how i can run Ajax code in my local computer. For example i am using the following code to get the text of a text file named data.txt:

    [HTML]<html>
    <head>
    <script>
    function submitForm()
    {
    var xhr;
    try { xhr = new ActiveXObject(' Msxml2.XMLHTTP' ); }
    catch (e)
    {
    try { xhr = new ActiveXObject(' Microsoft.XMLHT TP'); }
    catch (e2)
    {
    try { xhr = new XMLHttpRequest( ); }
    catch (e3) { xhr = false; }
    }
    }

    xhr.onreadystat echange = function()
    {
    if(xhr.readySta te == 4)
    {
    if(xhr.status == 200)
    document.ajax.d yn="Received:" + xhr.responseTex t;
    else
    document.ajax.d yn="Error code " + xhr.status;
    }
    };

    xhr.open(GET, "data.txt", true);
    xhr.send(null);
    }
    </script>
    </head>

    <body>
    <FORM method="POST" name="ajax" action="">
    <INPUT type="BUTTON" value="Submit" ONCLICK="submit Form()">
    <INPUT type="text" name="dyn" value="">
    </FORM>
    </body>
    </html> [/HTML]



    The file is located in the same directory where this HTML file is saved. When i click on the submit button i am getting an error on the line:


    [CODE=javascript]xhr.open(GET, "data.txt", true); [/CODE]

    the error is Get is undefined.

    please tell me how i can solve this problem. i am running this code on my local computer.

    waiting for reply.

    regards

    Mohammad Faisal
    Last edited by gits; Jun 25 '08, 06:35 AM. Reason: added code tags
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    put the GET in quotes ... otherwise it is considered as a variable and you get the shown error message ...

    kind regards

    Comment

    Working...