#39820 closed defect (bug) (invalid)
[Resolved] Can't change header status code response
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.7.2 |
Component: | General | Keywords: | |
Focuses: | Cc: |
Description
After update wordpress from 4.6.1 to 4.7.2 I was unpleasantly surprised.In ajax response like this:
<?php function post_contact_form($data) { $json_return = array(); if(!isset($data['name'])){ $error_status_header = 422; status_header($error_status_header); $json_return['error'] = __("Error. Please fill your name."); } else{ $json_return['success'] = __("Form submitted."); } echo json_encode($json_return); wp_die(); } add_action('wp_ajax_post_contact_form', 'post_contact_form'); add_action('wp_ajax_nopriv_post_contact_form', 'post_contact_form');
When I try to change status header to 422 , I just got http status header 200. In this case my fron-end logic was broked, because I check the ajax status code in ajax error handle. Also I tried with status code 400 the result is same. Please fix it because this bug has created extremely inconvenience to the functionality of my site.
Change History (7)
#4
@
6 years ago
- Resolution set to worksforme
- Status changed from new to closed
- Summary changed from Can't change header status code response to [Resolved] Can't change header status code response
Yes, it works! Thanks!
Note: See
TracTickets for help on using
tickets.
You should be able to send arguments to wp_die(). Response code can be sent to the title argument.
https://developer.wordpress.org/reference/functions/wp_die/
https://developer.wordpress.org/reference/functions/_ajax_wp_die_handler/
So if you use:
Or:
You should be able to change the response code.