var ajax = {
xhr: new XMLHttpRequest (),
request: function (method, url, vars) {
vars = JSON.stringify(vars);
vars = vars.replace(/\{/g, '').replace(/\}/g, '').replace(/\"/g, '').replace(/:/g, '=').replace(/,/g, '&');
ajax.xhr.open(method, url, true);
ajax.xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
ajax.xhr.send(vars);
},
response: function (res) {
ajax.xhr.onreadystatechange = function () {
return res(ajax.xhr.responseText);
};
},
get: function(url, vars, res) {
ajax.request('GET', url, vars);
ajax.response(res);
},
post: function(url, vars, res) {
ajax.request('POST', url, vars);
ajax.response(res);
}
};
/*
[object] ajax
[method] get|post
@param [string] url
@param [object/json] vars
@param [function] res (callback)
*/
ajax.post(
'login.php',
{
'username':'demo',
'password':'demo'
},
function (res) {
console.log(res);
}
);
This looks like a JavaScript file. Click this bar to format it.No 4
//javascript/8202