| | |
GetXmlHttpObject() for multiple objects
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2007
Posts: 30
Reputation:
Solved Threads: 1
Hello everyone,
I need to create several xmlHttp objects, but I only want to have one GetXmlHttpObject() function, so that I don't have to repeat for each object. Below code is definitely wrong because... how do I return the needed object from the GetXmlHttpObject() function?
Really appreciate,
M
I need to create several xmlHttp objects, but I only want to have one GetXmlHttpObject() function, so that I don't have to repeat for each object. Below code is definitely wrong because... how do I return the needed object from the GetXmlHttpObject() function?
Really appreciate,
M
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
var xmlHttp1 var xmlHttp2 var xmlHttp3 function showCustomer(str) { xmlHttp1=GetXmlHttpObject(); xmlHttp2=GetXmlHttpObject(); xmlHttp3=GetXmlHttpObject(); if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return; } var url1="getcustomer1.asp"; url1=url1+"?q="+str; url1=url1+"&sid="+Math.random(); var url2="getcustomer2.asp"; url2=url2+"?q="+str; url2=url+"&sid="+Math.random(); var url3="getcustomer3.asp"; url3=url3+"?q="+str; url3=url3+"&sid="+Math.random(); xmlHttp1.onreadystatechange=stateChanged; xmlHttp1.open("GET",url,true); xmlHttp1.send(null); xmlHttp2.onreadystatechange=stateChanged; xmlHttp2.open("GET",url,true); xmlHttp2.send(null); xmlHttp3.onreadystatechange=stateChanged; xmlHttp3.open("GET",url,true); xmlHttp3.send(null); } function stateChanged() { if (xmlHttp1.readyState==4 || xmlHttp2.readyState==4 || xmlHttp3.readyState==4) { document.getElementById("txtHint1").innerHTML=xmlHttp1.responseText; document.getElementById("txtHint2").innerHTML=xmlHttp2.responseText; document.getElementById("txtHint3").innerHTML=xmlHttp3.responseText; } } function GetXmlHttpObject() { var xmlHttp1=null; var xmlHttp2=null; var xmlHttp3=null; try { // Firefox, Opera 8.0+, Safari xmlHttp1=new XMLHttpRequest(); xmlHttp2=new XMLHttpRequest(); xmlHttp3=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp1=new ActiveXObject("Msxml2.XMLHTTP"); xmlHttp2=new ActiveXObject("Msxml2.XMLHTTP"); xmlHttp3=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp1=new ActiveXObject("Microsoft.XMLHTTP"); xmlHttp2=new ActiveXObject("Microsoft.XMLHTTP"); xmlHttp3=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; }
•
•
Join Date: Aug 2008
Posts: 381
Reputation:
Solved Threads: 33
In concept ...
By using a javascript-class approach, rather than a procedural approach you can instantiate multiple object instances of the class ... or you could simply reuse the same object-instance by passing different request-strings and even target (server-side-script) actions to the object.
I'm uploading my latest ajax class for you to play with ... it seems to be working but there may still be some bugs in it that I haven't found yet -- no promises.
Cheers
By using a javascript-class approach, rather than a procedural approach you can instantiate multiple object instances of the class ... or you could simply reuse the same object-instance by passing different request-strings and even target (server-side-script) actions to the object.
I'm uploading my latest ajax class for you to play with ... it seems to be working but there may still be some bugs in it that I haven't found yet -- no promises.
Cheers
Google is the answer to all of your questions -- the trick is knowing what question to ask in your specific predicament.
![]() |
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Force user action
- Next Thread: Tech help please.
| Thread Tools | Search this Thread |
ajax ajaxcode ajaxexample ajaxhelp ajaxjspservlets animate automatically browser bug calendar captchaformproblem checkbox child class close cookies createrange() cursor date debugger dependent disablefirebug dom dropdown editor element embed engine events explorer ext file form forms getselection google gxt hiddenvalue highlightedword hint html htmlform ie7 ie8 iframe image() images internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsf jsfile jump libcurl maps math media microsoft object onerror onmouseoutdivproblem onreadystatechange parent paypal pdf php player position post programming progressbar rated regex runtime safari scriptlets scroll search security session shopping size software sql star stars synchronous text textarea unicode validation web webservice website windowsxp wysiwyg \n





