XMLHttpRequest: send(null) but why?

Posted on 2006-05-31
Last Modified: 2012-06-21

I didn't think that the GET methods have sockets that needed to be closed.

-What does the send (null) function do?
-Why is it needed?
-When would you purposefully not use it?

 If you can, please provide an authoritative link to your source. Surprisingly,  I have had trouble finding good explanations for the methods associated with the XMLHttpRequest.

BONUS: In "XMLHttpRequest", How come XML is in caps but Http is not? It's very annoying.

Question by:0h4crying0utloud
    LVL 10

    Expert Comment

    Hi 0h4crying0utloud,

    Regarding the explanation and documentation, this is the best resource I've found so far:

    LVL 12

    Accepted Solution

    Well the example radarsh provided doesnt use the null at all.  

    "If you can, please provide an authoritative link to your source"
    As for link's your not gonna get any better than radarsh's.  

    "-What does the send (null) function do? && -Why is it needed?"
    It's the initation of the data being send to the server.  You can add headers and other things to the XMLHttpRequest and there is no way for the code to know when to send it untill you tell it to .send()

    -When would you purposefully not use it?
    Not use send?  um, when you dont want to send information to the server and only create an object that has the ability to.

    However i think that your more talking about the 'null' part.  When you use 'post', you can send you data using send(data).  This is when it's more than just text that can be appended to a url.  The best example i can think of is when you want to send a file to the server.

    So why do they use null when using get?  Well my guess is that send() and send(null) will both call the same function, bsically send() is just going to call the function send(variable) with the variable being null.  [Test out your own code with just a simple function]

    function Foo(stuff)

    LVL 10

    Author Comment


    I see, I thought open actually sent the request itself and send was something else. I found a good example of using the send for POST which I'll include here for historical purposes. :)

      var objHTTP, strResult;
      objHTTP = new ActiveXObject('Microsoft.XMLHTTP');



    A better reference site:
    LVL 12

    Expert Comment

    I think some of the points should of gone to radarsh because that link was very usefull.

    Oh and about the cap's thing.  XML always seems to be in caps. ( XMLDocument, XMLDOMDocument.....)

    And whent he last time u typed in HTTP://www....

    But the real question is the Html and HTML, which and when.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Both jQuery and Mootools offer some nice, easy to use scripts. Mootools is best known for their interactive slideshows and jQuery for their menus, but both have many other uses as well.   jQuery is basically a toolkit with many DOM (http://en.wik…
    Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now