WordPress sends invalid XML to jQuery .post

I am using WordPress which has jQuery 1.11.2 installed. The WordPress function should be doing all of the work to create valid XML, but jQuery is failing saying invalid XML. I’m not sure what’s wrong with the XML that it is doing that.

functions.php:

Read More
function prefix_ajax_add_foobar() {
    // Handle request then generate response using WP_Ajax_Response
    $response = array(
       'what'=>'foobar',
       'action'=>'update_something',
       'id'=>'1',
       'data'=>'<p><strong>Hello world!</strong></p>'
    );
    $xmlResponse = new WP_Ajax_Response($response);
    $xmlResponse->send();
}

ajax.js:

$.post( jln_vars.jln_public_ajax_url, {
        'action': 'add_foobar',
        'data':   'foobarid'
    }).done(function( data ) {
        alert('done');
        console.log( "Data Loaded: " + data );
    }).fail(function (jqXhr, status, error) {
        console.log(status + '------' + error + '------' + jqXhr.responseText);
    });

Console Log Response:

parsererror------Error: Invalid XML: 


<?xml version='1.0' encoding='UTF-8' standalone='yes'?><wp_ajax><response action='update_something_1'><foobar id='1' position='1'><response_data><![CDATA[<p><strong>Hello world!</strong></p>]]></response_data><supplemental></supplemental></foobar></response></wp_ajax>------


<?xml version='1.0' encoding='UTF-8' standalone='yes'?><wp_ajax><response action='update_something_1'><foobar id='1' position='1'><response_data><![CDATA[<p><strong>Hello world!</strong></p>]]></response_data><supplemental></supplemental></foobar></response></wp_ajax>

Related posts