Failed to load wp-admin/admin-ajax.php:1 resource: the server responded with a status of 400 (Bad Request) in Wordpress Ajax Call

Main Plugin File Code is:
wp_register_script('insertrating', plugin_dir_url( __FILE__ ) . 'js/dataInsertJ.js', array( 'jquery' ));
wp_localize_script( 'insertrating', 'insertrating_ajax', array( 'ajax_url' => admin_url('admin-ajax.php')) );
wp_enqueue_script("insertrating");
Code For DataInsertJ.js is
jQuery(document).ready(function(){
jQuery('#one').click(function(e) {
var postid = jQuery('#tihom-rating-post-id').val();
jQuery.ajax
({
url: insertrating_ajax.ajax_url,
data: {
"postid": postid,
"rating": 1
},
type: 'post',
success: function(result)
{
},
error: function( error ){
console.log("error");
alert("error");
}
});
});
});
I am getting an error "Failed to load wp-admin/admin-ajax.php:1 resource: the server responded with a status of 400 (Bad Request)"
Answer
Solution:
Solved this issue: as i need to add "action : 'some_action'" in "data"
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: warning: undefined array key
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.