We can write a function to check the status of your xmlhttp object:
var checkState = function(xmlhttp, callback) { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { callback(whatever, arguments, that, you, want, to, send); } else {
Then you can use it as follows:
checkState(xmlhttp, function(whatever, arguments, you, need) {
Two things:
- The checkState function will return regardless of readyState, so make sure you only do what depends on it in the callback, not after.
- If ReadyState and status never get your desired values, you're out of luck (but you can extend the function to accept a second callback that will time out).
Jakob source share