[wp-trac] [WordPress Trac] #39820: Can't change header status code response
WordPress Trac
noreply at wordpress.org
Thu Feb 9 07:41:28 UTC 2017
#39820: Can't change header status code response
--------------------------+-----------------------------
Reporter: skarabeq | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 4.7.2
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
After update wordpress from 4.6.1 to 4.7.2 I was unpleasantly surprised.In
ajax response like this:
{{{#!php
<?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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/39820>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list