Hello everyone,
I wrote an Ajax API, and I thought that it may be of some use to you all. I think that it's pretty self-explanatory. Post or PM me if you all need more or need help.
Peace!
-Stev
Hello everyone,
I wrote an Ajax API, and I thought that it may be of some use to you all. I think that it's pretty self-explanatory. Post or PM me if you all need more or need help.
Peace!
-Stev
/*
<!Tut
note: do not use "var" to declare x or req.
function makeReq()
{
target="http://yourserver.com/login.php";
data="yourdata=this&itsplace=thisstring";
req = new Request("post", target, true, data); /* method, address, async or not (true / false), optional: data. (it will auto detect)*/
req.rscAction = function() /* rsc = readystate call; when the readystate changes (req.request.onreadystatechange), the function that is executed.*/
{
if (this.status == 200 && this.readyState == 4)
{
document.getElementById('dispdiv').innerHTML = req.request.responseText;
}
};
req.ajaxSend();
}
*/
function Request(m, u, a, d)
{
var AjaxRequest = {
method: m,
url: u,
async: a,
data: d,
rscAction: function() {},
request: new XMLHttpRequest(),
ajaxSend: function () {
this.rscAction();
this.request.open(this.method, this.url, this.async);
if (this.data)
{
this.request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//this.request.setRequestHeader("Content-length", this.data.length);
//this.request.setRequestHeader("Connection", "close");
this.request.send(this.data);
}
else
{
this.request.send();
}
}
}
return AjaxRequest;
}
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.