//jQueryajax JSON
function ajax(obj){
var temp={
type:"get",
url:"-sharp",
data:{},
success:function(param){console.log(param)}
};
for(var key in obj){
temp[key]=obj[key];
}
var data="";
for(var key in temp.data){
data+=`${key}=${temp.data[key]}&`;
}
if(data){
data=data.substr(0,data.length-1);
}
var xhr=new XMLHttpRequest();
xhr.onreadystatechange=function(){
if(xhr.readyState===4){
if(xhr.status===200){
var param=JSON.parse(xhr.responseText);
temp.success(param);
}
}
};
var main=null;
if(temp.type==="get"){
temp.url+="?"+data;
}else{
main=data;
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
}
xhr.open(temp.type,temp.url,true);
xhr.send(main);
}