开发者

can't get AJAX get call to work even so the code seems correct

Ok fixed jQuery code with help of others on stack overflow

$(document).ready(function() {

   $(".note").live('click',function() {
      $("#note_utm_con").show();
      $("#note_utm_nt").html("<img src='http://www.ajaxload.info/images/exemples/4.gif' />");

      $.ajax({
         type: "GET",
         url: "view.php",
         data: "ajax=1&nid=' + parent.attr('id').replace('record-','')",
         success: function(html){
            $("#note_utm").html(html);
            $("#note_utm_nt").html("");
         },
         error: function (XMLHttp开发者_C百科Request, textStatus, errorThrown) {
            $("#note_utm_nt").html("<img src='http://www.ajaxload.info/images/exemples/4.gif' /> Error...");
        }
      });
   });
});

The PHP code for view.php

include 'object/db.class.php';

if($_GET['ajax'] == '1') {

#make a call to my sql to fetch some sort of ID

         $nid = $_GET['nid'];

         $q = mysql_query("SELECT * FROM `notice` WHERE nid = '".$nid."'");
         $a = mysql_fetch_array($q);

             $nid = stripslashes($a['nid']);
             $note = stripslashes($a['note']);
             $type = stripslashes($a['type']);
             $private = stripslashes($a['private']);
             $date = stripslashes($a['date']);
             $author = stripslashes($a['author']);

         $note_viewer .= <<<NOTE_VIEWER

         <h2>By: $author</h2> - <h2>$date</h2>
         <br/>
         <p>$note</p>
         <p>Request: $private</p>

NOTE_VIEWER;

             echo $note_viewer;


}

The AJAX seems to be working now as it gives me Error...


concerning the docu of jQuery, you attach an event with the live() method. In your code, you define the click-method of node twice, I think: once with the live-attaching-stuff and once with note.click(). So it is not clear what to do when clicking or better when node is clicked, the click-event is defined :-) You define two different actions when note is clicked... try this one:

$(document).ready(function() {

   $(".note").live('click',function() {
      $("#note_utm_con").show();
      $("#note_utm_nt").html("<img src='http://www.ajaxload.info/images/exemples/4.gif' />");

      $.ajax({
         type: "GET",
         url: "view.php",
         data: "ajax=1&nid=' + parent.attr('id').replace('record-',''),
         success: function(html){
            $("#note_utm").html(html);
            $("#note_utm_nt").html("");
         }
      });
   });
});


So what exactly is it doing? and What element is not visible? Your AJAX call isnt even using the response. If I understand your logic correctly, it should be...

$.ajax({
                   type: "GET",
                   url: "view.php",
                   data: "ajax=1&nid=' + parent.attr('id').replace('record-',''),
                   success: function(html){
                        $("#note_utm").html(html);
                        $("#note_utm_nt").html(html);
                   }
    });

the "html" variable in the success function is the response from the php script.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜