Debt Consolidation - Find jobs - Synchronize your Files - Debt Consolidation - Debt Consolidation

PDA

View Full Version : Extracting HTML with jQuery from AJAX XML response.


greboguru
Mar 16th 2008, 3:13 pm
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>




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);
}
});
});




Any help from you jQuery experts would be seriously welcome

Thanks!

decepti0n
Mar 17th 2008, 1:27 pm
var table = $("data", response).text();

Doesn't 'response' have the response anyway? What happens if you insert that straight into the table?

greboguru
Mar 17th 2008, 1:48 pm
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 17th 2008, 2:29 pm
**** Problem Resolved ****

Thanks!

russellneufeld
Sep 27th 2008, 6:14 pm
Hi greboguru,

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

Thanks,

Russ

temp_user
Apr 28th 2009, 11:43 pm
the xml was missing a > at the end of the CDATA