I am working on Wordpress and I have a strange error. This is my jQuery code
add_to_my_cart: function () {
$(document).on('submit', 'form.form-submit', function (event) {
event.preventDefault();
var data = $(this).serializeArray();
$.ajax({
url : wp_custom_settings.ajax,
type : 'POST',
data : data,
dataType: 'html',
success : function (code) {
code = parseJSON(code);
window.location.href = code.redirect;
}
});
});
}
The above is called when I submit a form and pass some data to the PHP function. However, I get a 500 internal server error
on admin-ajax HTTP request, with the following on apache logs.
Premature end of script headers: admin-ajax.php, referer: my.domain.here
AH01070: Error parsing script headers, referer: my.domain.here
I used the error_log($message)
in every step of the process and I haven't found any problem. The very last step is the return of the JSON request.
if ( ! function_exists( 'my_send_json' ) ) {
function my_send_json( $data ) {
error_log("DONE");
@header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
echo '<!-- WP_AJAX_START -->';
echo wp_json_encode( $data );
echo '<!-- WP_AJAX_END -->';
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
wp_die();
} else {
die;
}
}
}
I can see on the debug.log
the string DONE
, but the HTTP request has an empty response. I tried also to remove the $data
and just return this
echo wp_json_encode( array( 'status' => 'success', 'redirect' => 'my.domain.here' ));
But still the same. I cannot think of any other way to debug it.