我正在使用安装了jQuery 1.11.2的Wordpress。 Wordpress函数应该完成创建有效XML的所有工作,但是jQuery没有说无效的XML。我不确定它正在做的XML有什么问题。
的functions.php :
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);
});
控制台日志响应:
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>