加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Ajax面试题

发布时间:2020-12-15 21:58:14 所属栏目:百科 来源:网络整理
导读:Ajax步骤: html head title ajax example / title / head script type = "text/javascript" var req; function test() { req= new ActiveXObject( 'Microsoft.XMLHTTP' ); // 第一步 创建 XMLHttpRequest 对象 req.open( 'get' , 'server1.jsp' , true ); /

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读