请求 JSON 时获取“未定义不是一个函数”


Getting 'undefined is not a function' when requesting JSON

从PHP文件请求数据时遇到问题。

当我调用变量msg[0}时,我被告知它是未定义的,但它应该已填充在 JSON 请求中。JS在下面,你可以在链接中找到PHP输出:

$.ajax({
        type: "GET",
        url: "https://bluecode.org.uk/intranet/otd/index.php",
        dataType: "json"
      })
     .done(function (msg) {
      console.log(msg[0])
    });

实际的 PHP 是:

mysql_query("INSERT INTO uniquedownload (downloadkey, file, expires) VALUES ('{$strKey}',      'hello.html', '".(time()+(60*60*24*5))."')");
$a = array($strKey);
echo json_encode($a);

谢谢

我建议记录msg,以便您可以看到数据的外观,并可能在.done()回调中添加一个debugger;,以便为自己尝试访问msg属性的不同方法。

我需要将其添加到PHP中:

header('Content-Type: application/json');