douzhuo2002 2017-03-10 20:59
浏览 68

虽然我在检查器中看到数据,但无法使用PHP / Ajax / jSON填充select2

I developed a web application on Windows (XAMPP environment). Everything was working, but when I published it on a Linux Server I got a strange issue which is driving me mad. I've read all possible posts on SO, still i can't get the solution.

The problem is that all the select2 fields are not being updated by Ajax.

I am using select2 (ver. 3.x) populating it with jSON on searching. With PHP I return a jSON formatted set of data

header('Content-type: application/json');
...    
echo json_encode(array(
                'results' => $prepared_data,
                'more' => (@db_num_rows($res) >= $results_per_page),
                'elapsed' => round(microtime(true) - $start_ts, 3)
            ));

which is giving me a set of data in Chrome Inspector (Network -> Response) like:

{"results":[{"id":"8","text":"-- Scegli il Distretto --"},{"id":"3","text":"Distretto Centro"},{"id":"2","text":"Distretto Nord Est"},{"id":"1","text":"Distretto Nord Ovest"},{"id":"6","text":"Distretto Sardegna"},{"id":"7","text":"Distretto Sicilia"},{"id":"4","text":"Distretto Sud Est"},{"id":"5","text":"Distretto Sud Ovest"}],"more":false,"elapsed":0.109}

The only strange thing I notice is that before that string I can see a small dot in the Chrome network console response. Hovering it with the mouse I read it is \ufeff. There is no error in the console of Chrome, neither a network one.

Could anybody point me to the right direction in order to debug and possibly solve this issue?

  • 写回答

1条回答 默认 最新

  • duanmei1536 2017-03-11 18:32
    关注

    I answer my own question...

    The problem was a BOM mark at the beginning of a config.php file.

    What I did, on a Mac, was...

    1) With terminal cd into the app directory and:

    grep -rl $'\xEF\xBB\xBF'
    

    In this way I listed the files which had EF BB BF sequence at their beginning

    2) Downloaded a HEX editor such as HEX FIEND and removed the sequence in the files of the list (in my case just one).

    That's it. All was working after that!

    Fabio

    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测