simple ajax script problem

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

Join Date: Jun 2007
Posts: 2
Reputation: elduderino is an unknown quantity at this point 
Solved Threads: 0
elduderino elduderino is offline Offline
Newbie Poster

simple ajax script problem

 
0
  #1
Jun 10th, 2007
HI,

Im new here so hello all!

Im having this problem with a v simle ajax script.

Heres the code:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <title>test page</title>
  4. <script type="text/javascript" src="text-utils.js"></script>
  5. <script language="javascript" type="text/javascript">
  6.  
  7.  
  8. var request = null;
  9.  
  10. function createRequest() {
  11. try {
  12. request = new XMLHttpRequest();
  13. } catch (trymicrosoft) {
  14. try {
  15. request = new ActiveXObject("Msxml2.XMLHTTP");
  16. } catch (othermicrosoft) {
  17. try {
  18. request = new ActiveXObject("Microsoft.XMLHTTP");
  19. } catch (failed) {
  20. request = null;
  21. }
  22. }
  23. }
  24.  
  25.  
  26. if (request == null)
  27. alert("Error creating request object!");
  28. }
  29.  
  30. function get_message() {
  31. var message_id = document.getElementById("message_id").value;
  32. createRequest();
  33. var url = "edit_message.php?message_id=" + escape(message_id);
  34. request.open("GET", url, true);
  35. request.onreadystatechange = open_message;
  36. request.send(null);
  37.  
  38. }
  39.  
  40. function open_message() {
  41. if(request.readystate == 4) {
  42. var message_txt = request.responseText;
  43. var message_area = document.getElementById("message_text");
  44. replaceText(message_area, message_txt);
  45.  
  46. }
  47. }
  48.  
  49. </script>
  50. </head>
  51. <body>
  52. <table style="float: left; width: 30px; background-color: red;">
  53. <?php
  54. require_once('../mysql_connect.php');
  55. $sql = "SELECT * FROM message ORDER BY message_id";
  56. $query = mysql_query($sql);
  57. while($row = mysql_fetch_assoc($query)) {
  58. $message = $row['message'];
  59. $author = $row['author'];
  60. $message_id = $row['message_id'];
  61. ?>
  62.  
  63. <tr>
  64. <td><?php echo $message; ?></td><td><span style="color: red; font-weight: bold;"><?php echo $author; ?></span></td><td>
  65. <form method="GET">
  66. <input type="hidden" id="message_id" value="<?php echo $message_id; ?>">
  67. <input type="button" value="edit" onClick="get_message();" /></td> </form>
  68. </tr>
  69.  
  70.  
  71.  
  72.  
  73. <?php
  74.  
  75. }
  76.  
  77. ?>
  78. </table>
  79. <div style="float: left; width: 400px; margin-left: 20px; height: 400px; background-color: blue;" id="textbox">
  80. <p id="message_text">some text</p>
  81. </div>
  82.  
  83.  
  84. </body>
  85. </html>

Now all it should do is go off and get the message from the server and
put the text back in the textbox div. Now the edit_message.php script
works fine on itw own and returns what it should. Ive also looked at
the source and the right value is in the hidden input.



Problem is when you click on the edit button nothing happens!



can anyone spot my problemo??
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 2
Reputation: elduderino is an unknown quantity at this point 
Solved Threads: 0
elduderino elduderino is offline Offline
Newbie Poster

Re: simple ajax script problem

 
0
  #2
Jun 11th, 2007
haha stupid mistake!! want using capitals on the

if(request.readystate == 4)

it should have been

if(request.readyState == 4)



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



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC