Ajax面试题

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" οnchange="_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对象的引用(属性)。(用于扩展原对象属性

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值