下面用纯javascript来实现ajax
function runAjax(){
var xmlhttp;
var id = document.getElementById("xxx");
var content = document.getElementById("xxxx");
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=functioin(){
if(xmlhttp.status==200 && xmlhttp.readyState==4){
content.innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","ajax.Action?id="+id,true);
xmlhttp.send();
}
2,用JS来实现ajax:
$.ajax({
type:"GET",
url:"runAjax.action",
data:{"username":name}, //这里是传到后台的数据
success:function(result){
//成功后执行的函数
},
beforSend:function(){ //执行之前的函数},
complete:function(){ //完成之后执行的函数}
});