943,870 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1974
  • PHP RSS
Aug 19th, 2008
0

Ajax switch

Expand Post »
Hello everyone,

The ajax+php part worked well independently. When I created a switch (because I want different information from database to be displayed in different tabs), it does not go into the xmlHttp.onreadystatechange=function(). I tried all possible variations, and looked online for hours.

Can anyone help please?
Thank you


PHP Syntax (Toggle Plain Text)
  1. var moduleidd;
  2. var xmlHttp;
  3. function loadModules(moduleid, birdid)
  4. {
  5.  
  6. switch (moduleid)
  7. {
  8. case "contentA":
  9. document.getElementById("contentA").innerHTML = "Hello";
  10.  
  11.  
  12. case "contentB":
  13. {
  14.  
  15. xmlHttp=GetXmlHttpObject();
  16. var url= "contentB.php";
  17. url=url+"?q="+birdid;
  18. url=url+"&sid="+Math.random();
  19.  
  20. xmlHttp.onreadystatechange=function(){
  21.  
  22.  
  23. if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
  24. {
  25. document.getElementById("contentB").innerHTML = "test test test 123";
  26. var a = xmlHttp.responseText;
  27. document.getElementById("contentB").innerHTML = a;
  28.  
  29. }
  30. xmlHttp.open("GET",url,true);
  31. xmlHttp.send(null);
  32.  
  33. };
  34.  
  35. };
  36.  
  37. case "contentC":
  38. case "contentD":
  39. case "contentE":
  40.  
  41. }
  42.  
  43. }
  44.  
  45.  
  46.  
  47. function GetXmlHttpObject()
  48. {
  49. xmlHttp=null;
  50.  
  51.  
  52. try{
  53. //Firefox, Opera 8.0+, Safari
  54. xmlHttp=new XMLHttpRequest();
  55. }
  56. catch (e)
  57. {
  58. //Internet Explorer
  59. try
  60. {
  61. xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  62. }
  63. catch (e)
  64. {
  65. xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  66. }
  67. }
  68. return xmlHttp;
  69. }
Last edited by Mylena; Aug 19th, 2008 at 12:54 am. Reason: add a function
Similar Threads
Reputation Points: 10
Solved Threads: 1
Light Poster
Mylena is offline Offline
30 posts
since Jul 2007
Aug 19th, 2008
0

Re: Ajax switch

Are you sure, did you put an alert() in the function to see?
Reputation Points: 358
Solved Threads: 89
Posting Shark
R0bb0b is offline Offline
986 posts
since Jun 2008
Aug 19th, 2008
0

Re: Ajax switch

thanks for your reply,

yes, i put alert() function and it did not display. When i put alert() just before the no-working function, the alert displays. it's strange,...
Reputation Points: 10
Solved Threads: 1
Light Poster
Mylena is offline Offline
30 posts
since Jul 2007
Aug 19th, 2008
0

Re: Ajax switch

OOps, i solved it now, the closing brackets were wrongly aranged... how silly!
Reputation Points: 10
Solved Threads: 1
Light Poster
Mylena is offline Offline
30 posts
since Jul 2007
Aug 19th, 2008
0

Re: Ajax switch

Oh, you did fix it, OK cool.
Reputation Points: 358
Solved Threads: 89
Posting Shark
R0bb0b is offline Offline
986 posts
since Jun 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

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 PHP Forum Timeline: Chunk
Next Thread in PHP Forum Timeline: what is session





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


Follow us on Twitter


© 2011 DaniWeb® LLC