xmlhttp.readyState = 0 (why???)

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Nov 2007
Posts: 227
Reputation: k2k is an unknown quantity at this point 
Solved Threads: 0
k2k k2k is offline Offline
Posting Whiz in Training

xmlhttp.readyState = 0 (why???)

 
0
  #1
Jul 30th, 2009
hi,
basically i have this function.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function showDetail(checkBoxShipmentId)
  2. {
  3. xmlhttp = GetXmlHttpObject(); // this calls function below
  4. if (xmlhttp==null)
  5. {
  6. alert ("Browser does not support HTTP Request");
  7. return;
  8. }
  9.  
  10. var url="detailBackend.php";
  11. url=url+"?shipmentid="+checkBoxShipmentId; //?shipmentid = value of the checkbox, which is the shipmentid
  12. url=url+"&ran="+Math.random();
  13. if(xmlhttp.readyState ==4)
  14. {
  15. xmlhttp.onreadystatechange= displayDetail;
  16. xmlhttp.open("GET",url,true);
  17. xmlhttp.send(null);
  18. }
  19.  
  20. else
  21. {
  22. status = xmlhttp.readyState;
  23. alert(status); ///// this always return 0 /////
  24. }
  25.  
  26. }

which calls this function to initialize xmlhttp

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function GetXmlHttpObject()
  2. {
  3. if (window.XMLHttpRequest)
  4. {
  5. // code for IE7+, Firefox, Chrome, Opera, Safari
  6. return new XMLHttpRequest();
  7. }
  8.  
  9. if (window.ActiveXObject)
  10. {
  11. // code for IE6, IE5
  12. return new ActiveXObject("Microsoft.XMLHTTP");
  13. }
  14. return null;
  15. }


/******** i also have this function which is working *******/
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. var xmlhttp;
  2.  
  3. function showShipment(shipmentIdFromDropDown)
  4. {
  5. xmlhttp=GetXmlHttpObject();
  6. if (xmlhttp==null)
  7. {
  8. alert ("Browser does not support HTTP Request");
  9. return;
  10. }
  11. var url="responsexml.php";
  12. url=url+"?q="+shipmentIdFromDropDown;
  13. url=url+"&ran="+Math.random(); //generate a random number and store to variable ran to make sure cookie or session don't make them all the same
  14. xmlhttp.onreadystatechange=stateChanged;
  15. xmlhttp.open("GET",url,true);
  16. xmlhttp.send(null);
  17. }


Q: i am wondering if I have 2 functions calling the GetXmlHttpObject() function,,,, would that cause conflict or something? I really don't think it should.

Thanks for helping AJax newbie...
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 885
Reputation: Airshow will become famous soon enough Airshow will become famous soon enough 
Solved Threads: 127
Airshow's Avatar
Airshow Airshow is offline Offline
Practically a Posting Shark

Re: xmlhttp.readyState = 0 (why???)

 
0
  #2
Aug 1st, 2009
k2k,

The two calls to GetXmlHttpObject() will each cause an independent request objets to be returned and they should both work quite happily.

The only proviso is that if the two response handlers both affect the same js objects or the same areas of the DOM, then you could get "race effects", whereby two closely dispatched requests could respond in the reverse order and yield unexpected results.

However, in general this won't be an issue.

Airshow
50% of the solution lies in accurately describing the problem!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC