#39820 closed defect (bug) (invalid)
[Resolved] Can't change header status code response
| Reported by: | skarabeq | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | General | Version: | 4.7.2 |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
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
@
10 years ago
- Resolution → worksforme
- Status new → closed
- Summary Can't change header status code response → [Resolved] Can't change header status code response
Yes, it works! Thanks!
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
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/
if ( is_int( $args ) ) { $args = array( 'response' => $args ); } elseif ( is_int( $title ) ) { $args = array( 'response' => $title ); $title = ''; }So if you use:
Or:
You should be able to change the response code.