admin管理员组文章数量:1418306
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...
本文标签: phpResult from wpsendjson adds line feed
版权声明:本文标题:php - Result from wp_send_json adds line feed 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745282288a2651491.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论