我在wordpress中使用ajax,我做的每件事都做得很好,请告诉我为什么我的ajax返回0,即使代码是正确的。页面中是否有其他内容迫使ajax返回0。她的eis是我的js代码
jQuery(\'#seller-shop\').on(\'focusout\', function() {
var self = jQuery(this);
jQuery.ajax({
type: \'POST\',
url: script.axurl,
data: {"action": "wk_check_myshop","shop_slug":self.val(),"nonce":script.nonce},
success: function(resp)
{
console.log(resp);
if ( response == 0){
console.log(response);
}
}
});
});
php的代码是
add_action( \'wp_ajax_nopriv_wk_check_myshop\',array($mp_obj,\'wk_check_myshop_value\') );
add_action( \'wp_ajax_wk_check_myshop\',array($mp_obj,\'wk_check_myshop_value\'));
Thsi代码位于wp enqueue脚本挂钩内
wp_localize_script( \'marketplace\', \'script\', array( \'axurl\' => admin_url( \'admin-ajax.php\' ), \'nonce\' => wp_create_nonce(\'ajaxnonce\'), \'seller_page\' => $page_name , \'site_url\' =>site_url() ));