Extracting HTML with jQuery from AJAX XML response.

Discussion in 'jQuery' started by greboguru, Mar 16, 2008.

  1. #1
    Hi

    My response to my AJAX request is as follows

    
    
    <?xml version="1.0"?>
       <response>
          <status>0</status>
          <data>
            <![CDATA[<table><tr><td><a href="#"><img style="border:0;" src="image/b_del.png"/></a></td><td>16/03/2006</td></tr>
                <tr><td><a href="#"><img style="border:0;" src="image/b_del.png"/></a></td><td>1</td></tr></table>]]</data>
          <message></message>
       </response>
    
    
    Code (markup):

    I'm trying to extract the data table and insert it into a DIV on my page ... I'm not seeing anything? The code is (extract)...


    
    $.post("testEvent.php",
       { cmd: "ad", val: $("#newCourseDate").val() }, 
              function(response) 
              { 
                  if ($("status", response).text() != 0)
                  {
                     // something is not right
                     alert($("message", response).text());
                  }
                  else
                  {
                      // replace the existing dates with the new ones
                      $("#eventDates").empty();                            
                      var table  = $("data", response).text();
                      $("#eventDates").html(table);
                  }
              });
    });
    
    
    Code (markup):

    Any help from you jQuery experts would be seriously welcome

    Thanks!
     
    greboguru, Mar 16, 2008 IP
  2. decepti0n

    decepti0n Peon

    Messages:
    519
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #2
    var table  = $("data", response).text();
    PHP:
    Doesn't 'response' have the response anyway? What happens if you insert that straight into the table?
     
    decepti0n, Mar 17, 2008 IP
  3. greboguru

    greboguru Member

    Messages:
    78
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #3
    Hi,

    Thanks for the response. If I insert the whole of the response I get the status field appearing as well. I just want to extract the data part and effectively inserting the <table> contained within it, into a DIV.

    Thanks for your time

    gG
     
    greboguru, Mar 17, 2008 IP
  4. greboguru

    greboguru Member

    Messages:
    78
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #4
    **** Problem Resolved ****

    Thanks!
     
    greboguru, Mar 17, 2008 IP
  5. russellneufeld

    russellneufeld Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hi greboguru,

    I'm having the same problem you were having. How did you solve it?

    Thanks,

    Russ
     
    russellneufeld, Sep 27, 2008 IP
  6. temp_user

    temp_user Guest

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    the xml was missing a > at the end of the CDATA
     
    temp_user, Apr 28, 2009 IP