www.webdeveloper.com
Results 1 to 2 of 2

Thread: getHTTPObject();

  1. #1
    Join Date
    Apr 2011
    Posts
    17

    getHTTPObject();

    Got this snippet of code, but getHTTPObject(); is not valid.
    What .js library need to get this working?

    <script src="json2.js"></script>
    var request;
    function runAjax(JSONstring)
    {
    // function returns "AJAX" object, depending on web browser
    // this is not native JS function!
    request = getHTTPObject();
    request.onreadystatechange = sendData;
    request.open("GET", "parser.php?json="+JSONstring, true);
    request.send(null);
    }

    // function is executed when var request state changes
    function sendData()
    {
    // if request object received response
    if(request.readyState == 4)
    {
    // parser.php response
    var JSONtext = request.responseText;
    // convert received string to JavaScript object
    var JSONobject = JSON.parse(JSONtext);

    // notice how variables are used
    var msg = "Number of errors: "+JSONobject.errorsNum+
    "\n- "+JSONobject.error[0]+
    "\n- "+JSONobject.error[1];

    alert(msg);
    }
    }

  2. #2
    Join Date
    Nov 2010
    Posts
    86
    Hi, Basically that function would just create a XMLHttpRequest object, presumably checking if it needs to use the older style (ie 5+6) ActiveX method instead. You can get good and brief explanation of it here.

    http://www.w3schools.com/ajax/ajax_x...est_create.asp

    In short, your getHTTPObject() function would do something like this:

    Code:
    function getHTTPObject()
    {
      if (window.XMLHttpRequest) return new XMLHttpRequest();
      else return new ActiveXObject("Microsoft.XMLHTTP");
    }
    Note I haven't tested this so there may be a typo or something.

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