Bad request 400 from custom ajax call

There’s only one reason you get a 400 error with admin-ajax.php: The wp_ajax_{$action} or wp_ajax_nopriv_{$action} action has not been hooked with an {$action} that matches the action data parameter sent with your request. So either your callback is not hooked, or you’re not sending the action correctly. Your code is making both errors.

  1. You are encoding the data sent to the server as JSON. WordPress looks for $_REQUEST['action'] to trigger the appropriate action. When data is sent to the server as JSON, $_REQUEST cannot be populated, so $_REQUEST['action'] does not exist, meaning that your callback is never run. You need to remove JSON.stringify() from your code.
  2. You are running add_action() for wp_ajax_myblog_ajax_request inside a page template. This won’t work. You are sending your request to wp-admin/admin-ajax.php, but that code does not load templates, so your callback is not hooked for that request. You need to use add_action() inside a file that is loaded inside wp-admin/admin-ajax.php, such as your theme’s functions.php file, or a plugin.