943,822 Members | Top Members by Rank

Ad:
Jul 30th, 2009
0

xmlhttp.readyState = 0 (why???)

Expand Post »
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...
Similar Threads
k2k
Reputation Points: 15
Solved Threads: 1
Posting Whiz
k2k is offline Offline
351 posts
since Nov 2007
Aug 1st, 2009
0

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

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
Sponsor
Reputation Points: 318
Solved Threads: 358
WiFi Lounge Lizard
Airshow is online now Online
2,526 posts
since Apr 2009
Jan 19th, 2011
0

XMLHTTPRequest status=0 resolution

Other than all the obvious errors on the client side, the main reason for this is that gecko engine looks for the Access-Control-Allow-Origin in the header from the servlet. If it does not find it, it will abort the communication and you get a status=0 and statusText=null. Also, the moz-nullprincipal in xml parsing error. All of this stuff is very misleading. All you need to resolve this problem is:

response.setHeader("Access-Control-Allow-Origin","*");

In the servlet code and life will be good :-)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
MOZANDY is offline Offline
1 posts
since Jan 2011
Jan 19th, 2011
0
Re: xmlhttp.readyState = 0 (why???)
MozAndy,

This discussion probably belongs elsewhere but here goes .....

It's probably me but I'm struggling to see the relevance of your answer (interesting though it is) to K2K's question.
  • Question is about multiple ajax requests.
  • Access-Control-Allow-Origin header is about cross-domain (cross-origin) issues.
Given that K2K's code uses relative urls, surely same-domain (same-origin) must apply.

Hence, an Access-Control-Allow-Origin header appears not to be necessary, and in any case irrelevant to solving issues with multiple simulatneous ajax requests.

What am I missing?

Airshow
Sponsor
Reputation Points: 318
Solved Threads: 358
WiFi Lounge Lizard
Airshow is online now Online
2,526 posts
since Apr 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Adsense not loading, has anyone found a solution yet?
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: JQuery replaceWith





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC