jQuery and WP_Ajax_Response

I tried to use WP_Ajax_Response class to respond Ajax request, but then some data wrap with [CDATA], and found that I just can’t use jQuery .text() to grab the data inside that… here is how i resolved this problem

<?xml ....?>
<wp_ajax>
...
<supplemental>
<url><!&#91;CDATA&#91;http://.....&#93;&#93;></url>
</supplemental>
</wp_ajax>
var xml = $.parseXML(response),
    imgURL = $(xml).find('supplemental url').text()

first use jQuery function to parse the response, then use jQuery .text() method to retrieve the data within CDATA.

Post to Twitter Post to Plurk Post to Yahoo Buzz Post to Delicious Post to Digg Post to Facebook Post to MySpace Post to Ping.fm Post to Reddit Post to StumbleUpon

One thought on “jQuery and WP_Ajax_Response

Leave a Reply