Ajax wp_update_post() throws an error 500?

Comes Ajax request, to update post, this is the code of the file for update, try to do so:
$product_id = $_POST['product_id'];
$product_new_menu_order = $_POST['product_new_menu_order'];

$product = array(
 'ID' => $product_id ,
 'menu_order' => $product_new_menu_order,
);

$post_id = wp_update_post( $product, true );
if (is_wp_error($post_id)) {
$errors = $post_id->get_error_messages();
 foreach ($errors as $error) {
 echo $error;
}
}


Tried hooks:
update_my_product function() {
 $product = array(
 'ID' => $product_id ,
 'menu_order' => $product_new_menu_order,
);
 wp_update_post( $product );
wp_die();
}

add_action('wp_ajax_update_product', 'update_my_product');
add_action('wp_ajax_nopriv_update_product', 'update_my_product');


JS Ajax:

jQuery(document).ready(function($) {

 $(document).on('change', '#menu_order', function(event) {

 var plugin_url = $(this).data('url'),
 product_id = $(this).data('product-id'),
 product_new_menu_order = $(this).val();

$.ajax({
 url: plugin_url,
 type: 'POST',
 data: {
 'action': 'update_product',
 'product_id': product_id,
 'product_new_menu_order': product_new_menu_order,
},
})
 .done(function(data) {
console.log(data);
console.log("success");
})
 .fail(function() {
console.log("error");
});


});
});


Look in the console, XHR Google chrome error 500 and all of prevthe no.
I do not understand why knocks error?
August 19th 19 at 23:24
2 answers
August 19th 19 at 23:26
Solution
in the $product_id and $product_new_menu_order you pass a string and have (int)$product_id and (int)$product_new_menu_order for
https://github.com/WordPress/WordPress/blob/f3a9d2...
https://github.com/WordPress/WordPress/blob/f3a9d2...

Plus not critical in this case, but it is always necessary to add the check for and clean
I also second file and forgot to connect, where the actual code update. - Adalberto.Blick commented on August 19th 19 at 23:29
August 19th 19 at 23:28
Look in the server logs (Apache, for example).
<b></b> $errors = $post_id->get_error_messages();
the interpreter will not be processed, are you sure that there can be such characters?
this accident here added, in the source no - Adalberto.Blick commented on August 19th 19 at 23:31
in any case 500 can be seen in the server logs - Adalberto.Blick commented on August 19th 19 at 23:34
: : and where can they see if I have access only to the ftp site and the admin? - Lucius commented on August 19th 19 at 23:37
: as an option to deploy a working copy of the website on the local machine and debug already at - Adalberto.Blick commented on August 19th 19 at 23:40

Find more questions by tags AJAXWordPress