| | |
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.
Views: 4234 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
ajax ajaxexample ajaxjspservlets array autoplay blackjack browser captcha captchaformproblem cart child class close codes date debugger dependent developer disablefirebug dom editor element embed engine enter events explorer ext file firefox flash focus form forms game gears getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe java javascript javascripthelp2020 jquery jsf jsp jump libcurl maps margin marquee masterpage math media menu object onerror onmouseoutdivproblem onreadystatechange parent passing paypal pdf php player position post programming prototype rated redirect safari scale scriptlets scroll search security size software solutions sources star stars stretch synchronous toggle tweet unicode variables web webkit webservice window \n





