Wordpress向jQuery.post发送无效的XML
我正在使用Wordpress,它安装了jQuery1.11.2。Wordpress函数应该完成所有创建有效XML的工作,但jQuery无法说出无效XML。我不确定XML有什么问题,因为它正在这样做 functions.php:Wordpress向jQuery.post发送无效的XML,jquery,ajax,wordpress,Jquery,Ajax,Wordpress,我正在使用Wordpress,它安装了jQuery1.11.2。Wordpress函数应该完成所有创建有效XML的工作,但jQuery无法说出无效XML。我不确定XML有什么问题,因为它正在这样做 functions.php: function prefix_ajax_add_foobar() { // Handle request then generate response using WP_Ajax_Response $response = array( 'w
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();
}
$.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>
控制台日志响应:
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();
}
$.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>
parsererror-----错误:无效的XML:
你好,世界]>------
你好,世界]>
我决定改用wp_send_json:注意到类似的问题,您使用的是PHP7吗?我决定改用wp_send_json:注意到类似的问题,您使用的是PHP7吗?