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?
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?
Share Improve this question asked Mar 17, 2015 at 10:56 strattonnstrattonn 1791 silver badge5 bronze badges 1- 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 Commented Mar 19, 2015 at 1:04
1 Answer
Reset to default 0Well 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...
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745282289a4620346.html
评论列表(0条)