0

I've got a local Windows stack running AMPPS at 5.4.35 and my code runs fine but when I deploy to my Bluehost server running PHP 5.4.28 the execution of wp_send_json is different.

wp_send_json( array('error' => 'Please enter a valid postcode.', 'errorFieldType'=>'postcode') );

Works fine on Windows but on Bluehost, if I debug in Chrome there is a line feed added to the beginning of the response. If I open it in Chrome's console I get this.

response
"
{"error":"Please enter a valid postcode.","errorFieldType":"postcode"}"

On Windows alert(response.error); shows the error, on Bluehost I get "undefined".

Any ideas what's going on?

  • My guess is, coming from Windows, my php script has carriage return-line feeds, where as unix only has line feeds. The php interpreter is giving me back a left over carriage return in my output which is put at the beginning of the response. – strattonn Mar 19 '15 at 1:04
0

Well that was tricky. This was the offending code that was generated a line feed to the response.

add_action('wp_ajax_nopriv_display_event_info', 'DisplayEventInfoBox');
?>

<?php
function displayStepHeader($isValid, $pos)

I changed it to

add_action('wp_ajax_nopriv_display_event_info', 'DisplayEventInfoBox');

function displayStepHeader($isValid, $pos)

and all is well. I have no idea why that was an issue but how I tracked it down may be useful for someone else. I simply put echo 'a'; between the function definitions until the first character I received was an 'a' and not char 10 (line feed).

This was also caused "Warning: Cannot modify header information - headers already sent" because the first character sometimes wasn't < but a line feed.

Hopes this helps someone else out one day...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.