AJAX--js

JavaScript 中:

function ajax(){

var xmlHttpRequerst;

try{

 xmlHttpRequest = new XMLHttpRequest(); // code for IE7+, Firefox, Chrome, Opera, Safari

}catch(e){

xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");// code for IE6, IE5

}

//执行

xmlHttpRequest.onreadystatechange(function(){

if(xmlHttpRequest.readyState==4 && xmlHttpRequest.status==200)//readyState (0/1/2/3/4) ;status(200/404)

document.getElementsById("ID").innerHTML(xmlHttpRequest.responseText);//xmlHttpRequest.responseText or xmlHttpRequest.responseXML返回参数

})

//设置参数

xmlHttpRequest.open("GET","URL?parm="+"参数",true);// open(method,url,true)1:method --can be GET or POST;2:parm --get from form;

//发送

xmlHttpRequest.send();

posted @ 2013-01-30 11:20  roscee  阅读(167)  评论(0编辑  收藏  举报