944,093 Members | Top Members by Rank

Ad:
Jun 10th, 2007
0

simple ajax script problem

Expand Post »
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??
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
elduderino is offline Offline
2 posts
since Jun 2007
Jun 11th, 2007
0

Re: simple ajax script problem

haha stupid mistake!! want using capitals on the

if(request.readystate == 4)

it should have been

if(request.readyState == 4)



Reputation Points: 10
Solved Threads: 0
Newbie Poster
elduderino is offline Offline
2 posts
since Jun 2007

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: Opening New Blank Window from within Pop-up
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Connecting To External Javascript File





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


Follow us on Twitter


© 2011 DaniWeb® LLC