I have created public rest endpoint with POST method and when I try ajax or use insomnia always response with 403 forbidden nginx. Why isn’t this working and how could I resolve my problem?
Route:
add_action('rest_api_init', 'registerContactPOST');
function registerContactPOST(){
register_rest_route('fb/v1', 'contact',
array(
'methods' => 'POST',
'callback' => 'contactPOST',
'permission_callback' => '__return_true'
)
);
}
function contactPOST($requestData){
return 'ok';
}
Client ajax:
<script>
jQuery.ajax( {
url: '/wp-json/fb/v1/contact',
method: 'POST',
data:{
'xyz' : 'xyz'
}
} ).done( function ( response ) {
console.log( response );
} );
</script>
In xampp localhost it works fine but not with remote server.