onreadystatechange do nothing
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: onreadystatechange do nothing

  1. #1
    Join Date
    May 2005
    Posts
    178

    onreadystatechange do nothing

    i wrote-
    function updateEventItems(value)
    { var xmlObj=null;

    if (window.XMLHttpRequest)
    xmlObj=new XMLHttpRequest();
    else if (window.ActiveXObject)
    xmlObj=new ActiveXObject("Microsoft.XMLHTTP");
    else return;

    xmlObj.onreadystatechange=function()
    { if(xmlObj.readyState==4) alert("ok");
    }
    }

    and in some component i have added-
    onchange="updateEventItems(this.value)"

    i guess im missing something because im not getting the "ok" alert
    what is wrong ?
    thanks in advanced.

  2. #2
    Join Date
    Sep 2006
    Posts
    28

    Re: onreadystatechange do nothing

    Because you are saying when the file is ready then do whatever is inside that function. If you are not sending anything to the file, then you wont get the alert box. Create an empty file, and then add the following lines to the end:
    Code:
    xmlObj.open ("POST", "./file.ext", true);
    xmlObj.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
    xmlObj.send (null);
    then you should get the alert box, because javascript went to the page, did something (in this case just returned an empty file), and it came back successfully, so you should get the alert box.

    And one other thing, your xmlObj should be this:
    Code:
    var xmlObj = (window.ActiveXObject) ? new ActiveXObject ("Microsoft.XMLHttp") : new XMLHttpRequest();

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center