www.webdeveloper.com
Results 1 to 3 of 3

Thread: AJAX open('GET',url,true) returns undefined value

Hybrid View

  1. #1
    Join Date
    Mar 2013
    Posts
    2

    AJAX open('GET',url,true) returns undefined value

    I'm learning AJAX myself and my code is

    <html>
    <head>
    <script>
    function callAjax()
    {
    var xmlreq = new XMLHttpRequest(); // since i'm using Mozilla
    var url = "http://localhost/naga/get_details.php?name=naga";
    var ope;
    ope = xmlreq.open('GET',url,true);
    alert(ope); // here i'm getting as 'undefined'
    xmlreq.onreadystatechange = myFunc();
    function myFunc()
    {
    if (xmlreq.readyState==4)
    {
    document.getElementById('one').innerHTML=xmlreq.responseText;
    }
    }
    xmlhttp.send();
    }
    </script>
    </head>
    <body>
    <div id="one">Microsoft</div>
    <input type="button" onclick="callAjax()" value="Change link">

    </body>
    </html>

  2. #2
    Join Date
    Mar 2009
    Posts
    495
    So far as I know, the "open" method/function of an httpXMLrequest object has no return value. The question is whether it gets the value from the server for you.

  3. #3
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    Quote Originally Posted by Tcobb View Post
    So far as I know, the "open" method/function of an httpXMLrequest object has no return value. The question is whether it gets the value from the server for you.
    from spec:
    Code:
     void open(ByteString method, DOMString url, optional boolean async = true, optional DOMString? user = null, optional DOMString? password = null);
    so yeah, undefined is to be expected.

    change xmlreq.onreadystatechange = myFunc(); to xmlreq.onreadystatechange = myFunc; if you want the code to work as expected.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles