SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: AJAX problem

Threaded View

  1. #1
    SitePoint Wizard
    Join Date
    Oct 2005
    0 Post(s)
    0 Thread(s)

    AJAX problem


    This isnt strictly a php question as all the php involved works fine but i figured the php forum would be the best to post this question in as opposed to the javascript forum. If theres somewhere more appropriate for this Mr Moderator then please move it.

    I have a script here:

    Code JavaScript:
    <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;
       	var url = "edit_message.php?message_id=" + escape(message_id);"GET", url, true);
       	request.onreadystatechange = open_message;
       function open_message() {
       	if(request.readystate == 4) {
       		var message_txt = request.responseText;
       		var message_area = document.getElementById("message_text");
       		replaceText(message_area, message_txt);
     <table style="float: left; width: 30px; background-color: red;">
    $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'];
      		<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>
      <div style="float: left; width: 400px; margin-left: 20px; height: 400px; background-color: blue;" id="textbox">
      <p id="message_text">some text</p>

    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??

    Last edited by elduderino; Jun 10, 2007 at 13:11.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts