Created
October 24, 2013 22:18
-
-
Save Hoff97/7146111 to your computer and use it in GitHub Desktop.
Simple to use Ajax Object.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function AjaxRequest(_file, _readyFunction, _parameters) //A Ajax request wich sends parameter with POST | |
{ | |
var file = _file; | |
var readyFunction = _readyFunction; | |
var parameters = _parameters; | |
this.send = function() | |
{ | |
var xmlhttp; | |
if (window.XMLHttpRequest) | |
{ | |
xmlhttp=new XMLHttpRequest(); | |
} | |
else | |
{ | |
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); | |
} | |
xmlhttp.onreadystatechange=function() | |
{ | |
if (xmlhttp.readyState==4 && xmlhttp.status==200) | |
{ | |
readyFunction(xmlhttp); | |
} | |
else if(xmlhttp.status==404) | |
{ | |
alert("Request failed. Page not found\nStopped at readyState: " + x | |
} | |
} | |
xmlhttp.open("POST",file,true); | |
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); | |
var sendparams = ""; | |
for(var a = 0; a<parameters.length; a++) | |
{ | |
if(a>0) | |
{ | |
sendparams += "&"; | |
} | |
sendparams += parameters[a].name + "=" + parameters[a].value; | |
} | |
xmlhttp.send(sendparams); | |
} | |
} | |
function Parameter(_name, _value) | |
{ | |
this.name = _name; | |
this.value = _value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment