admin管理员组文章数量:1315851
My usual ajax function looks like this:
function get_modal_playlist_classplan( $odv_video_id ) {
check_ajax_referer($_REQUEST['nonce'], "my_cool_nonce", false);
$result['type'] = "success";
$result['message'] = "Booooo";
if ( $some_test === true ) {
$result['message'] = "Yay";
}
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$result = json_encode($result);
echo $result;
} else {
header("Location: " . $_SERVER["HTTP_REFERER"]);
}
die();
}
How do I replace my approach with the use of wp_send_json_success (and wp_send_json_error)?
I tried replacing $result['message'] = "yay"
with:
$return = array(
'message' => 'yay',
'some_other_data' => $_REQUEST['hello'] . ' world'
);
wp_send_json_success( $return );
But the ajax request fails.
本文标签: ajaxUsing wpsendjsonsuccess instead of result39message39dieetc
版权声明:本文标题:ajax - Using wp_send_json_success instead of $result['message'], die, etc 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741986807a2408728.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论