Ajax基础课后练习及答案 下载本文

Ajax 基础 课后练习

一、选择题

1、以下不是 Ajax 主要技术的是( )。 a) JavaScript b) XML c) CSS d) JUnit

2、下面( )不是 XMLHttpRequest 对象的方法。 a) open() b) send() c) readState d) responseText

3、 Ajax 的关键元素包括( )。 a) JavaScript

b) DOM 文档对象 c) CSS 样式表

d) XMLHttpRequest 对象

4、创建 XMLHttpRequest 对象的部分代码如下,请在空白处填入关键代码( )。 //?省略的代码

if(window.XMLHttpRequest){

xmlHttpRequest=________________ }else{

xmlHttpRequest=_________________ }

a) new XMLHttpRequest();

new ActiveXObject(“Microsoft.XMLHTTP”); b) new XMLHttpRequest(); new ActiveXObject();

c) new ActiveXObject(“Microsoft.XMLHTTP”); new XMLHttpRequest(); d) new ActiveXObject(); new XMLHttpRequest();

5、以下是 Ajax 的 XMLHttpRequest 对象属性的有( )。 a) onreadystatechange b) abort

c) responseText d) status

6、 当 XMLHttpRequest 对象的状态发生改变时调用 callBackMethod 函数, 下列正确的是( )。

a) xmlHttpRequest.callBackMethod=onreadystatechange; b) xmlHttpRequest. onreadystatechange(callBackMethod);

c) xmlHttpRequest. onreadystatechange(new function(){callBackMethod }); d) xmlHttpRequest. onreadystatechange= callBackMethod;

7、 XMLHttpRequest 对象的 readyState 属性值为( )时,代表请求成功数据接收完毕。 a) 0 b) 1 c) 2 d) 3 e) 4

8、 XMLHttpRequest 对象的 status 属性表示当前请求的 http 状态码,其中( )表示正确返 回。 a) 200 b) 300 c) 500 d) 404

二、简答题

1.请简述使用 GET 请求并获取服务器端返回的文本信息的过程。 2、请简述使用 Ajax 的优点?

Ajax 基础 课后练习参考答案

一、选择题 1 2 3 4 5 6 7 8 d cd abcd a acd d e a 二、简答题

1. (1)创建请求字符串

var url=”servlet/doLogin?uname=zhangsan&pwd=123”; (2)创建 XMLHttpRequest 对象

xmlHttpRequest =new XMLHttpRequest();//IE7 及以上版本或其他浏览器

xmlHttpRequest=new ActiveXObject(“Microsoft.XMLHTTP”);//老版本 IE( IE5 和 IE6)

(3)设置回调函数

xmlHttpRequest.onreadystatechange=回调函数名 ;

在回调函数中使用 xmlHttpRequest 的 responseText 获得返回的文本信息。 (4)初始化 XMLHttpRequest

xmlHttpRequest.open(“GET”,url,true); (5)发送请求

xmlHttpRequest.send(null);

2、 使用 Ajax 的最大优点,就是能在不更新整个页面的前提下维护数据。这使得 Web 应用程序更为迅捷地回应用户动作,并避免了在网络上发送那些没有改变过的信息。从而更加优化了用户体验度。 Ajax 不需要任何浏览器插件, 但需要用户允许 JavaScript 在浏览器上执行。