FAQ about Ajax-Part II

Source: Internet
Author: User

About the script in my page: Ajax Asynchronous JavaScript and XML.

Q:
Why do u create an http_request_check? What's the use?
A:
The object http_request_check is an object through which we send our request to the server side. and with the traditional way, we will send our reqeust to server through submitting a form. but Ajax makes it different.

Q:
How can I send my request to a specified server?
A:
We can use method
Http_request_check.open (para1: sendway, para2: serverurl, para3: asychronousely | synchronouly)
Para1: to specify how to send the response to server. There are two ways: "Get" and "Post ".
Para2: to specify the server URL where the request sends to and the response reply back from.
Para2: To specify send request asychronousely or sychronousely. The default is asycronousely.

Q:
How can we invoke the callback function when the response from server arrives.
A:
The request object has a event called readystatechange. we must associate this event hanlder with a involved function. that is to say, when the reqeust object track that the event of readystatechange, it will invoke the callback function aotumaticly. the grammer is like this:
Http_request_check.onreadystatechange = mycallback_function;
Function mycallback_function ()
{
......
}

Q:
In our self-difinited callback function processrequest_check (), why do we write like this:
If (http_request_check.readystate = 4)
{......}
To judge the http_request_check's readystate?
A:
Http_request_check has readystate, which is like, 3 4 ,.... only state 4 means that the server response has arrived. that's it. actually, we can handle something only after the server response has arrived.

q:
readystate 4 means that server resposne has arrived. but what about the
If (http_request_check.status = 200)
{< br> ......
}< br> why we need to judge it again?
A:
OK, just now we said readystate 4 means the server response has arrived. But how about the result? Maybe the result is an error exception! How to judge it? Then we must check the http_request_check.status. you know, there are so busy status about http_request, such as 402,403,404 ,... 200. each one indicates one kind of result. and only status 200 means status normal with no exception. so if we wanna handle the page, we must guarantee that the server response is OK. that's the reason.

Q:
How can we get the content from the server response through http_request_check object?
A:
When the server response has arrived. The http_request_check has a property called responsetext, and in which the reply content is contained. So if we wann get the response content, just write like this:
* *** = Http_request_check.responsetext.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.