Php wordpress ajax调用在调用一次后继续运行
我制作了一个wordpress ajax调用代码,当我点击一个按钮时,函数会正常运行,并第一次返回它应该返回的值,但在那之后,对admin-ajax.php keepon的ajax调用会运行,正如我从开发工具中看到的那样。我的代码是Php wordpress ajax调用在调用一次后继续运行,php,jquery,ajax,wordpress,Php,Jquery,Ajax,Wordpress,我制作了一个wordpress ajax调用代码,当我点击一个按钮时,函数会正常运行,并第一次返回它应该返回的值,但在那之后,对admin-ajax.php keepon的ajax调用会运行,正如我从开发工具中看到的那样。我的代码是 add_action( 'wp_ajax_arete_bp_endorse', 'arete_bp_endorse_ajax' ); add_action( 'wp_ajax_nopriv_arete_bp_endorse', 'arete_bp_endorse_a
add_action( 'wp_ajax_arete_bp_endorse', 'arete_bp_endorse_ajax' );
add_action( 'wp_ajax_nopriv_arete_bp_endorse', 'arete_bp_endorse_ajax' );
function arete_bp_endorse_ajax(){
global $wpdb;
$result['type'] = "works";
echo $result;
wp_die();
}
function my_script_enqueuer() {
wp_register_script( "my_voter_script", WP_PLUGIN_URL.'/example/js/example.js', array('jquery') );
wp_localize_script( 'my_voter_script', 'myAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' )));
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'my_voter_script' );
}
example.js文件代码
jQuery(document).on("click",".endorse-bt", function (event){
event.preventDefault();
var type= jQuery(this).attr("data");
var option= jQuery(this).parents("li").attr("data-endorsed-item-name");
var profile_id=jQuery(this).parents("li").attr("data-prf-id");
var login_id=jQuery(this).parents("li").attr("data-lg-id");
jQuery.ajax({
dataType : "json",
url : myAjax.ajaxurl,
type: 'POST',
data:{action: "arete_bp_endorse", type : type, option: option, profile_id: profile_id, login_id: login_id},
success: function( response ){
//Do something with the result from server
alert(response.type);
}
});
});
我不确定是否对你有效。你是说它一次又一次地发送ajax请求,还是只是请求一直挂起?它完成了它应该执行的请求,然后再次发送请求