douran9707 2013-05-29 14:45
浏览 61
已采纳

不返回JSON数据

The problem is that the alert message "TEST" does not appear, although the function getData.php is successfully executed and returns some data. I checked it in Firelog, where I can see the following output:

Array{"arr":[["1","EZY14ZM","2013-05-29 16:44:38","2013-05-29 16:45:28"],["1","VLG1307","2013-05-29 16:47:05","2013-05-29 16:47:55"],["1","WZZ212","2013-05-29 16:49:12","2013-05-29 16:50:02"]],"dep":[["1","VLG8306","2013-05-29 16:59:17","2013-05-29 17:00:00"],["1","VLG3786","2013-05-29 17:07:29","2013-05-29 17:08:12"],["1","IBE1851","2013-05-29 17:08:38","2013-05-29 17:09:21"],["1","DLH58Y","2013-05-29 17:09:47","2013-05-29 17:10:30"]]}

How to solve this problem?

function show_data() {
 $.getJSON(
    'h_index.php?module=mod_1&pag_mod=getData.php',
    function(data) {
       alert("TEST");
    }
 );             
}

getData.php

<?php
   //...
   echo json_encode(array('arr' => $rows_arr, 'dep' => $rows_dep););
   die();
?>
  • 写回答

1条回答 默认 最新

  • 普通网友 2013-05-29 14:50
    关注

    Quote: your data as viewed in Firebug:

    Array{"arr":[["1","EZY14ZM","2013-05-29 16:44 .....
    

    Note the Array at the start of that..... this is not valid JSON.

    The actual json_encode() function you're calling is fine. It does have an extra stray semi-colon, but that's invalid PHP syntax, so I assume it's crept in when you posted the question rather than being in your actual code.

    So the stray text Array is not being produced by the json_encode() function, so it must be coming from somewhere else in your PHP. Look for an echo or a print elsewhere in your code that is outputting it by mistake. (probably by printing an array variable rather than the actual string "Array")

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料