When coding some JavaScript to send a POST (instead of a GET) back to the webserver, I wondered whether you need to define the XMLHttp.onreadystatechange? My code so far looks like this:
XMLHttp.onreadystatechange = function(){};
XMLHttp.open("POST", "http://something.com/receiver.php", true);
XMLHttp.setRequestHeader("Content-type", "text/plain");
XMLHttp.send("blabla");
because I don’t need to do anything when the POST has succeded, and so don’t need any functionality to be triggered.
Question 1:
I want to make the code as short as possible, and I’ve thought about setting onreadystatechange = null, anybody knows whether this would work (in all browsers)?
Question 2:
I guess it wouldn’t be safe to leave onreadystatechange undefined altogether… it might have a predefined value on some systems… anybody knows about this?
Thanks guys!
Actually, instead of setting
onreadystatechangeto null, you can just leave it out, and nothing will happen.