dqrm8199 2014-04-14 13:54
浏览 32

Jquery mobile从.php文件获取json在本地工作但不在服务器上工作

i am working on a Jquery mobile project and want to load a json. The json comes from a .php file. The problem is that it will not load.

My .php file looks like this.

<?php
    $query=mysql_query("SELECT * FROM `data`");
    while($data=mysql_fetch_assoc($query))
    $output['result'] []=$data;
    header('Content-Type: application/json', true);
    echo json_encode($output);  
?>

I tried 2 different methods inside my jquery:

$.ajax({
    url: "http://www.example.com/jsonfile.php",
    dataType : "json"
}).success(function(data){

$.getJSON('http://www.example.com/jsonfile.php', function(data) {

Here is a little recap. When using a local .json file everything works. But when i call the same file on the server it does not. The error i get is:

The character encoding of the plain text document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the file needs to be declared in the transfer protocol or file needs to use a byte order mark as an encoding signature.

In my .php file i can get rid of this error using: header('Content-Type: application/json; charset=US-utf-8');

Even without the error in my .php both files won't work. (my database is utf8_general_ci)

  • 写回答

2条回答 默认 最新

  • duanmei1894 2014-04-14 15:28
    关注

    PHP white screen or no data is sign of an script error. Your ajax calls are correct, it's recomendable enable error reporting on development environment, so you need to check error logs or enable error_reporting to get the exception.

    评论

报告相同问题?

悬赏问题

  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法