FAQ about AJAX-part II
2008-04-12 19:54
197 查看
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 send 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 many readystate,which is like 1,2,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)
{
......
}
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 many 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.
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 send 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 many readystate,which is like 1,2,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)
{
......
}
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 many 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.
相关文章推荐
- 使用WIF实现单点登录Part II —— Windows Identity Foundation基本原理 -摘自网络
- WTL for MFC Programmers, Part II - WTL GUI Base Classes
- TCP/IP FAQ 1
- Flash Recovery Area - FAQ (文档 ID 833663.1)
- FastDFS -- FAQ
- Sql FAQ
- std::function and std::bind(find in FAQ)
- Android【USB名称修改系列】第1项-为什么参考FAQ修改名称后却无效
- FAQ:如何提高编译速度?
- C++11 FAQ中文版:控制默认函数——默认或者禁用
- C++11 FAQ中文版:std::function 和 std::bind
- Android & Eclipse FAQ
- Python FAQ
- Design pattern FAQ Part 2
- FAQ
- [FAQ04549] JB Launcher2 代码导入Eclipse 后如何消除错误
- Lambda FAQ_2.为什么在Java中加入Lambda表达式?
- Lambda FAQ_7.Lambda表达式的域规则是什么?
- Lambda FAQ_15.如何解决方法声明之间的冲突
- Lambda FAQ_17.Java的集合要去向何方