我已经尝试使ajax请求工作了一段时间了。当我不尝试发送任何数据时,它会起作用。这是我的javascript
$(document).on('click','.next-page',function(){
var page = $(this).data('page');
var ajaxUrl = $(this).data('url');
var ajaxRequest = $.ajax({
url : ajaxUrl,
method : 'POST',
data : {
page : page,
action : 'portfolio_theme_pagination'
}
});
ajaxRequest.done(function(msg){
//do something
});
ajaxRequest.fail(function(jqXHR, status,error){
//do something else
console.log(jqXHR,status,error);
});
});
});
这是html文件,数据im传递到了我的javascript文件
<div class="col-lg-4">
<div class="next-posts text-center">
<p><a class="btn btn-default next-page" data-page="1" data-url="<?php echo admin_url('admin-ajax.php'); ?>">NEXT</a></p>
</div>
</div>
这是我在名为ajax.php的functions.php文件中解开的php文件
add_action('wp_ajax_nopriv_porfolio_theme_pagination','portfolio_theme_pagination');
add_action('wp_ajax_porfolio_theme_pagination','portfolio_theme_pagination');
function portfolio_theme_pagination() {
//pagination funcitonality
return 'hello world';
wp_die(); //ALWAYS
}
控制台显示statusText:400 并且readyState = 4