I am using a very simple form request to and verify it through the wp_verify_nonce() function. It is working perfectly on the desktop. But not working on mobile devices( iPhone, Andriod ). Could someone help me to identify the issue?
HTML Code
<form action="" method="POST" id="test-form" novalidate="novalidate">
<?php wp_nonce_field( 'irw_gzip_action', 'irw_gzip_field' ); ?>
</form>
JavaScript
var $self = $(this);
var $nonce = $('#irw_gzip_field', $self).val();
$.ajax({
url: WT.ajaxurl,
type: 'POST',
datatype: 'json',
data: {
_ajax_nonce: $nonce,
action: 'check_action'
}
})
PHP Code
add_action( 'wp_ajax_nopriv_check_domain', array( $this, 'handle_domain_request' ) );
add_action( 'wp_ajax_check_domain', array( $this, 'handle_domain_request' ) );
public function handle_domain_request() {
if ( ! isset( $_POST['_ajax_nonce'] ) ||
! wp_verify_nonce( $_POST['_ajax_nonce'], 'irw_gzip_action' )
) {
return wp_send_json( array(
'error' => 'Un-Authorized request!'
), 401);
}
}
Complete Codes:
Javascript:
HTML:
PHP:
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742250008a4408965.html
评论列表(0条)