Uncaught ReferenceError: param is not defined occurs when simulating jQ encapsulating ajax, calls

//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);
}
Mar.04,2021

refer to introduction to Ajax (2) encapsulation of Ajax function . It is recommended not to pursue the same API as jQ at the beginning, but to achieve the function ~


first.

/ / simulated jQuery encapsulation ajax does not consider cross-domain and the default return data type is 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;
}
xhr.open(temp.type,temp.url,true);
if(temp.type==='post'){
    main=data;
    xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded,charset=UTF-8 ');
}
xhr.send(main);

}

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bdf35c-3147b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bdf35c-3147b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?