maina
Version:
35 lines • 1.13 kB
JavaScript
function Ajaxfz(obj){
var method=obj.method || "get";
var url=obj.url || "";
var async=obj.async || true;
var data=obj.data || null;
var success=obj.success || function (){}
if(window.XMLHttpRequest){
var xhr=new XMLHttpRequest();
}else{
var xhr=new ActiveXObject("Microsoft.XMLHTTP");
}
if(method.toLowerCase()=="get"){
xhr.open(method,url+"?"+data,async);
xhr.send(null);
}else if(method.toLowerCase()=="post"){
xhr.open(method,url,async);
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xhr.send(data);
}
xhr.onreadystatechange=function(){
if(xhr.readyState==4&&xhr.status==200){
success(xhr.responseText)
}
}
}
Ajaxfz({
method:"get",
url:"a.json",
async:true,
data:"name=zs&sex=男",
success:function(response){
console.log(response);
}
})
module.exports.fzajax();