ajax response not recieving
Question
Will anyone help me in this regard. My problem is that when I ajax request WordPress, when I log that response in console it shows error/complete
not response
.
jQuery(document).ready(function($) {
$(".pincode_search_field").on('keyup', function(event) {
event.preventDefault();
var ajax_url = pin_shop.ajax_url;
var pincode_search_field = $(this).val();
var nonce = $(this).data('nonce');
$.ajax({
url: ajax_url,
type: 'POST',
dataType: 'json',
data: {
'action' : 'pincode_search_field',
'nonce' : nonce,
'search_query' : pincode_search_field,
},
})
.done(function(response) {
console.log(response);
console.log('success');
})
.fail(function() {
console.log("error");
})
.always(function() {
console.log("complete");
});
});
});
Here is my PHP code.
add_action( "wp_ajax_pincode_search_field", 'pincode_search_field' );
add_action( "wp_ajax_nopriv_pincode_search_field", 'pincode_search_field' );
function pincode_search_field() {
global $wpdb;
if ( wp_verify_nonce( $_REQUEST['nonce'], "pin_shop_nonce") ) {
$result['database_result'] = $wpdb->get_results("SELECT ID FROM cs_shop_details WHERE pincode = '192124'");
$result = json_encode( $result );
die();
}
}
0
ajax, custom-post-types, plugin-development
4 years
2020-05-27T01:10:38-05:00
2020-05-27T01:10:38-05:00 0 Answers
73 views
0
Leave an answer