XMLHttpRequest: send(null) but why?

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.

LVL 10
Who is Participating?
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)

Hi 0h4crying0utloud,

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


0h4crying0utloudAuthor Commented:

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:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.