Why they write the get method of ajax like this?

J

jidixuelang

aj.get = function(targetUrl, resultHandle) {
aj.targetUrl = targetUrl;
aj.XMLHttpRequest.onreadystatechange =
aj.processHandle;
aj.resultHandle = resultHandle;
if(window.XMLHttpRequest) {
aj.XMLHttpRequest.open('GET', aj.targetUrl);
aj.XMLHttpRequest.send(null);
} else {
aj.XMLHttpRequest.open("GET", targetUrl, true);
aj.XMLHttpRequest.send();
}
}



Some one tell me this is a standard?

Why they write the "get" method like this?

if(window.XMLHttpRequest) {
aj.XMLHttpRequest.open('GET', aj.targetUrl);
aj.XMLHttpRequest.send(null);
} else {
aj.XMLHttpRequest.open("GET", targetUrl, true);
aj.XMLHttpRequest.send();
}

But not directly write

aj.XMLHttpRequest.open('GET', aj.targetUrl);
aj.XMLHttpRequest.send(null);

what is the difference???
 
V

VK

On Jul 15, 4:43 pm, "(e-mail address removed)"
Why they write the "get" method like this?

if(window.XMLHttpRequest) {
aj.XMLHttpRequest.open('GET', aj.targetUrl);
aj.XMLHttpRequest.send(null);
} else {
aj.XMLHttpRequest.open("GET", targetUrl, true);
aj.XMLHttpRequest.send();
}

Who are "they"? sounds scary :)
The code above is an ugly Cargo Cult coding sample. The bottom brunch
was originally intended for IE - it is still visible by send() instead
of send(null) statement. But obviously the text passed through a
number of people having no clue what are they saying (doing), so now
it is all mixed up and it is what it is: a pointless chunk of
statements.
 
R

Richard Cornford

aj.get = function(targetUrl, resultHandle) {
aj.targetUrl = targetUrl;
aj.XMLHttpRequest.onreadystatechange =
aj.processHandle;
aj.resultHandle = resultHandle;
if(window.XMLHttpRequest) {
aj.XMLHttpRequest.open('GET', aj.targetUrl);
aj.XMLHttpRequest.send(null);
} else {
aj.XMLHttpRequest.open("GET", targetUrl, true);
aj.XMLHttpRequest.send();
}
}



Some one tell me this is a standard?

It is not.
Why they write the "get" method like this?
if(window.XMLHttpRequest) {
aj.XMLHttpRequest.open('GET', aj.targetUrl);
aj.XMLHttpRequest.send(null);
} else {
aj.XMLHttpRequest.open("GET", targetUrl, true);
aj.XMLHttpRequest.send();
}

Don't write that, it is silly.
But not directly write

aj.XMLHttpRequest.open('GET', aj.targetUrl);
aj.XMLHttpRequest.send(null);

what is the difference???

The - open - method of XML HTTP request objects is expecting three
arguments; the third stating whether the request is asynchronous or not.
For some season someone has decided that whenever a -
window.XMLHttpRequest - object exists they not going to provide that
third argument. Presumably they are assuming that under those
circumstances the third argument will harmlessly default to an
acceptable value. It is very unlikely that this assumption is valid or
safe.

Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top