I'm using AJAX to send instructions to a PHP script that result in various database operations. In the PHP script, I force an HTTP response code and reason text. The PHP portion of this part is working, as I can see both the code and reason text when I explore the header in Chrome's developer tools. However, back in the JQuery AJAX call, I can only access the status code. The response text is always generic.
I have tried many variations found here and elsewhere, but none of the jqXHR properties I've explored contain the custom status response text the PHP script sends back.
I've also tried setting the header access controls as suggested in the post I found on here, even though I am not implementing anything cross-domain. It produced no results the one time I tried.
Here is the AJAX call:
function set_logger_command(user_input)
{
$.ajax({
type: "POST",
url: './logger_cmd_processor.php',
data: {cmd_input:user_input},
statusCode:
{
201: function(responseObject, textStatus, jqXHR)
{
// Created (201)
// This code will be executed if a new log was successfully created
document.getElementById("status-container").innerHTML=jqXHR.status + " | " + textStatus;
document.getElementById("paper").innerHTML=jqXHR.responseText;
},
419: function(responseObject, textStatus, errorThrown)
{
// Service Unavailable (503)
// This code will be executed if the server returns a 503 response
alert(jqxhr.status);
}
}
})
And Here is the PHP that sets the response header:
// Sets the HTTP response status code and message
function set_http_response ($code,$message)
{
$phpSapiName = substr(php_sapi_name(), 0, 3);
if ($phpSapiName == 'cgi' || $phpSapiName == 'fpm') {
header('Status: '.$code.' '.$message);
} else {
$protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
header($protocol.' '.$code.' '.$message);
}
}
As an example, if in PHP I set the response header to "Status: 201 table created successfully!" I expect that when the AJAX call is complete jqXHR.status would be "201" (and that does work), and textStatus would be "table created successfully".
Instead, the textStatus just contains "Success"
Any suggestion or help will be appreciated. Thanks