Ajax面试题

来源:互联网 发布:北京世纪中彩网络诈骗 编辑:程序博客网 时间:2024/06/05 20:05

Ajax步骤:

<html>

<head>

 <title>ajax example</title>

</head>

<scripttype="text/javascript">

var req;

 function test()

 {

 req=newActiveXObject('Microsoft.XMLHTTP'); //第一步创建XMLHttpRequest对象

 req.open('get','server1.jsp',true);//第二步open//get方式提交,sever1.jsp提交路径,true表示异步请求

 req.onreadystatechange=callback; //第三步定义确定回调函数

//根据状态变化触发事件,调用callback函数,状态值readyState

readyState的取值如下:

0 (未初始化)
1 (
正在装载)
2 (
装载完毕)
3 (
交互中)
4 (
完成)

 req.send(null);//Asynchronized thread //第四步 send

 }

 function callback()

 {

  var state=req.readyState;

  if(state==4)

  {

   var data = req.responseText;//从页面返回数据

   varxmlData=req.responseXML;//获取xml数据

   var emp=xmldata.getElementsByTagName("emp");

   var v=emp[0].getElementByTagName("empname")[0].firstchild.date;

   fillinfo(data);

  }

 }

 function fillinfo(message)

 {

    var info=document.getElementById('info');//获取Html节点

    info.innerHTML(message);

 }

</script>

<body>

  <inputtype=buttonvalue='click me'onclick='test()'><br>//触发事件

  <divid='info'></div>

</body>

</html>

 

 

1.如何获取表单select域的选择部分的文本?

<form name="a">

 <select name="a" size="1" onchange="_sel(this)">

   <option value="a">1</option>

   <option value="b">2</option>

   <option value="c">3</option>

 </select>

</form>

 

function _sel(obj){

alert("显示文本:" + obj.options[obj.selectedIndex].text);

alert("值:" + obj.options[obj.selectedIndex].value);

}

 

2.在JavaScript中定时调用函数 foo()如何写?

 

function foo(){

alert("aaaa");

a = setTimeout(foo(),100);

}

foo();

 

1.       请介绍一下XMLHttpRequest对象?

通过XMLHttpRequest对象,Web开发人员可以在页面加载以后进行页面的局部更新。

AJAX开始流行始于Google在2005年使用的”GoogleSuggest”。

2.      Ajax请求总共有多少种Callback?
Ajax请求总共有八种Callback
onSuccess
onFailure
onUninitialized
onLoading
onLoaded
onInteractive
onComplete
onException

3.      Prototype(原型)

javascript中约定了每个对象都可以包含一个prototype对象的引用(属性)。(用于扩展原对象属性

原创粉丝点击