Ok basicly I want a function where I can enter several parameters, and be able to use this function multiple times. This is an example of what I want, first commented.
Also note i am aiming for high efficiency.
It is really the third parameter that is the part I need the most help with.
An example of use is:
So you get the idea, of how I want to be able to use it. The third parameter is a reference to which function to call on retrieval of the data.
Now using bits and pieces of the net. I have an attempt at queryurl.js (this is the part i need help on / my question is on) - this is incomplete and could possibly be more efficient:
I get the feeling the post method wont work, offcourse im rather unsure about most of this.
Thanks in advance, Josh
Also note i am aiming for high efficiency.
Code:
function QueryUrl(type, url, returnFunction){
// where type is a choice between post and get.
// url is obviously the url you want to retrieve information from
// returnFunction is a function that will be run, and passed across the returned data as a parameter (when it has retrieved the data)
}
An example of use is:
Code:
QueryUrl('POST', 'tryregister.php', updateNow);
function updateNow(returnedData){
document.getElementById('main_content').innerHTML = returnedData;
}
Now using bits and pieces of the net. I have an attempt at queryurl.js (this is the part i need help on / my question is on) - this is incomplete and could possibly be more efficient:
Code:
function QueryUrl(type, url, returnFunction){
var xmlHttp=GetXmlHttpObject();
if (xmlHttp==null){
alert ("Browser does not support HTTP Request");
return;
}
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open(type,url,true);
xmlHttp.send(null);
function stateChanged(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
returnFunction(xmlHttp.responseText);
}
}
function GetXmlHttpObject(){
var xmlHttp=null;
try{
xmlHttp=new XMLHttpRequest();
}catch (e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}catch (e){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
}
Thanks in advance, Josh
Comment