封装ajax
function ajax_(_type,_url,_data,callback,_dataType){
_dataType=_dataType==undefined?"text":_dataType;
$.ajax({
type:_type,
url:_url,
async:true,
data:_data,
dataType:_dataType,
success:callback(data),
})
}
注意:需要引入jQuery
ajax get
var xml=new XMLHttpRequest();
xml.open("GET","index.php?bigId="+bigId+"&_id="+_id,true);
xml.send();
xml.onreadystatechange=function(){
if(xml.readyState==4 && xml.status==200){
var news=JSON.parse(xml.responseText);
}
}
ajax post
var xml=new XMLHttpRequest();
xml.open("POST","index-1.php?",true);
xml.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xml.send("city="+_city);
xml.onreadystatechange=function(){
if(xml.readyState==4 && xml.status==200){
div.innerHTML=xml.responseText;
}
}