ajax的基础:XMLHttpRequest对象
发布时间:2020-12-16 01:47:08 所属栏目:百科 来源:网络整理
导读:1、XMLHttpRequest 用于在后台与服务器交换数据,是实现ajax请求的核心对象,创建XMLHttpRequest的方式(考虑浏览器兼容性): var xmlhttp; if ( window .XMLHttpRequest){ // code for IE7+,Firefox,Chrome,Opera,Safari xmlhttp= new XMLHttpRequest(); } e
1、XMLHttpRequest 用于在后台与服务器交换数据,是实现ajax请求的核心对象,创建XMLHttpRequest的方式(考虑浏览器兼容性): var xmlhttp;
if(window.XMLHttpRequest){// code for IE7+,Firefox,Chrome,Opera,Safari
xmlhttp=new XMLHttpRequest();
}else{// code for IE6,IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
2、XMLHttpRequest对象的方法、向服务器发送请求的方式 方法: get请求:
xmlhttp.open("GET","demo_get2.asp?fname=Bill&lname=Gates",true);
xmlhttp.send();
post请求:
xmlhttp.open("POST","ajax_test.asp",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("fname=Bill&lname=Gates");
3、XMLHttpRequest对象的属性、对服务的响应 通过属性变化,获取服务器的响应数据: (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |