what is the function of "ajaxObj." ? could u give me an example..
if(ajaxObj.... )//i don't understand in this part
{
document.getElementById("divResult").innerHTML = ajaxObj.responseText;
}
what is the function of "ajaxObj." ? could u give me an example..
if(ajaxObj.... )//i don't understand in this part
{
document.getElementById("divResult").innerHTML = ajaxObj.responseText;
}
It's very hard if not impossible to answer this question on the basis of the information you've given, but: Perhaps you're talking about the XMLHttpRequest
object. It's job is to send a GET or POST (or sometimes other verbs) request to the server and receive the response, without doing a page refresh. For instance, when you submit a comment on a question or answer here on StackOverflow, an XHR (as they're frequently called) is used to send your comment to the server rather than requiring the entire page to be reloaded.
XHR isn't very hard to use directly, but it's even easier to do this if you use a library like Prototype, jQuery, Closure, or any of several others that will handle some browser idiosyncracies for you and generally make the API a bit simpler.
Edit Based on your updated question:
My guess was probably correct: ajaxObj
is probably an instance of XMLHttpRequest
, since responeText
is one of the XMLHttpRequest
properties. (Or it might be a Prototype Ajax.Response
, as they used the same name; other frameworks may have done something similar.)
What that code is doing is checking to see if the ajaxObj
variable refers to something and, if so, the code replaces the content of the divResult
div with the markup that the server sent back in response to the request (looking up the element by ID and then setting its innerHTML
property).
It's just the name of a variable, could have been called blablabla
as well.
Judging by the fact that they refer to ajaxObj.responseText
I would say that it's some sort of AJAX framework object (maybe homemade) and responseText
is the response of the AJAX call.
You should look for the definition of responseTextajaxObj
.