80LK

Untitled

Dec 4th, 2020
531
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function ajax(settings){
  2.     let request = new XMLHttpRequest();
  3.     let data = new FormData();
  4.  
  5.     request.open(settings.method||"get", settings.url, settings.async || false);
  6.     if(settings.method == "post"){
  7.         request.setRequestHeader("ContentType", "application/x-www-form-urlencoded; charset=utf-8")
  8.     }
  9.     request.onreadystatechange = function(){
  10.         if(request.readyState == 4)
  11.             settings.ready?.apply(this);
  12.         else
  13.             settings.upload?.apply(this);
  14.     }
  15.  
  16.     for(let i in settings.data)
  17.         data.append(i, settings.data[i]);
  18.  
  19.     request.send(data);
  20. }
  21.  
RAW Paste Data