User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 392,007 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,204 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1189 | Replies: 1
Reply
Join Date: Jun 2007
Posts: 2
Reputation: elduderino is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
elduderino elduderino is offline Offline
Newbie Poster

simple ajax script problem

  #1  
Jun 10th, 2007
HI,

Im new here so hello all!

Im having this problem with a v simle ajax script.

Heres the code:

<html>
<head>
<title>test page</title>
<script type="text/javascript" src="text-utils.js"></script>
<script language="javascript" type="text/javascript">
 

   var request = null;

   function createRequest() {
     try {
       request = new XMLHttpRequest();
     } catch (trymicrosoft) {
       try {
         request = new ActiveXObject("Msxml2.XMLHTTP");
       } catch (othermicrosoft) {
         try {
           request = new ActiveXObject("Microsoft.XMLHTTP");
         } catch (failed) {
           request = null;
         }
       }
     }
   

     if (request == null)
       alert("Error creating request object!");
   }

   function get_message() {
   	var message_id = document.getElementById("message_id").value;
    createRequest();
   	var url = "edit_message.php?message_id=" + escape(message_id);
   	request.open("GET", url, true);
   	request.onreadystatechange = open_message;
   	request.send(null);
  
   }

   function open_message() {
   	if(request.readystate == 4) {
   		var message_txt = request.responseText;
   		var message_area = document.getElementById("message_text");
   		replaceText(message_area, message_txt);

   	}
   }
		
</script>
</head>
<body>
 <table style="float: left; width: 30px; background-color: red;">
<?php
require_once('../mysql_connect.php');
$sql = "SELECT * FROM message ORDER BY message_id";
$query = mysql_query($sql);
while($row = mysql_fetch_assoc($query)) {
  $message = $row['message'];
  $author = $row['author'];
  $message_id = $row['message_id'];
  ?>
 
  	<tr>
  		<td><?php echo $message; ?></td><td><span style="color: red; font-weight: bold;"><?php echo $author; ?></span></td><td>
  		<form method="GET">
  		<input type="hidden" id="message_id" value="<?php echo $message_id; ?>">
  		<input type="button" value="edit" onClick="get_message();" /></td> </form>
  	</tr>

  	
 

  <?php 

}

?>
  </table>
  <div style="float: left; width: 400px; margin-left: 20px; height: 400px; background-color: blue;" id="textbox">
  <p id="message_text">some text</p>
  	</div>


</body>
</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??
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2007
Posts: 2
Reputation: elduderino is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
elduderino elduderino is offline Offline
Newbie Poster

Re: simple ajax script problem

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 10:21 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC