admin管理员组文章数量:1022719
I spend a lot of time searching for a solution to this issue. I looked on google and stackexchange but didn't get the answer.
So I am looking for the solution is while making an ajax request through my plugin(that I am developing) i am getting this 400 status error. I don't know why i am getting this?
1 Scripts
function smn_admin_assets($page_now){
if( $page_now == "settings_page_smn_notice" ){
wp_enqueue_style( 'smn-admin-style', plugins_url( "../assets/admin/admin.css", __FILE__ ) );
wp_enqueue_script( 'smn-admin-js', plugins_url( "../assets/admin/admin.js", __FILE__), array( 'jquery' ), VERSION, true );
$pass_value = array(
'url' => admin_url( 'admin-ajax.php' ),
'cookieNonce' => wp_create_nonce('cookieNonce')
);
wp_localize_script('smn-admin-js', 'smn_ajax', $pass_value );
}
}
add_action( 'admin_enqueue_scripts', 'smn_admin_assets' );
2 Ajax Request
$(document).ready(function () {
$("#clearCookie").on('click', function(){
var clearCookie = $('#clearCookie').val();
// Ajax Call
$.ajax({
url : smn_ajax.url,
type : 'POST',
data : {
action : 'smn_clear_cookie',
clearcookie : clearCookie
},
success : function( response ) {
alert('Hello');
},
error: function () {
alert(smn_ajax.url);
}
});
return false;
});
});
3 Ajax Handling
function smn_clearCookie(){
$clearCookie = $_POST['clearCookie'];
var_dump($clearCookie);
die();
}
add_action( 'wp_ajax_smn_clear_cookie', 'smn_clearCookie' );
add_action( 'wp_ajax_nopriv_smn_clear_cookie', 'smn_clearCookie' );
Let me know why i am getting this error; Thank you for your time.
I spend a lot of time searching for a solution to this issue. I looked on google and stackexchange but didn't get the answer.
So I am looking for the solution is while making an ajax request through my plugin(that I am developing) i am getting this 400 status error. I don't know why i am getting this?
1 Scripts
function smn_admin_assets($page_now){
if( $page_now == "settings_page_smn_notice" ){
wp_enqueue_style( 'smn-admin-style', plugins_url( "../assets/admin/admin.css", __FILE__ ) );
wp_enqueue_script( 'smn-admin-js', plugins_url( "../assets/admin/admin.js", __FILE__), array( 'jquery' ), VERSION, true );
$pass_value = array(
'url' => admin_url( 'admin-ajax.php' ),
'cookieNonce' => wp_create_nonce('cookieNonce')
);
wp_localize_script('smn-admin-js', 'smn_ajax', $pass_value );
}
}
add_action( 'admin_enqueue_scripts', 'smn_admin_assets' );
2 Ajax Request
$(document).ready(function () {
$("#clearCookie").on('click', function(){
var clearCookie = $('#clearCookie').val();
// Ajax Call
$.ajax({
url : smn_ajax.url,
type : 'POST',
data : {
action : 'smn_clear_cookie',
clearcookie : clearCookie
},
success : function( response ) {
alert('Hello');
},
error: function () {
alert(smn_ajax.url);
}
});
return false;
});
});
3 Ajax Handling
function smn_clearCookie(){
$clearCookie = $_POST['clearCookie'];
var_dump($clearCookie);
die();
}
add_action( 'wp_ajax_smn_clear_cookie', 'smn_clearCookie' );
add_action( 'wp_ajax_nopriv_smn_clear_cookie', 'smn_clearCookie' );
Let me know why i am getting this error; Thank you for your time.
版权声明:本文标题:plugins - WordPress Ajax request "Failed to load resource: the server responded with a status of 400 ()" 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745527929a2154612.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论