Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么我的php代码会出现Server500错误_Javascript_Php - Fatal编程技术网

Javascript 为什么我的php代码会出现Server500错误

Javascript 为什么我的php代码会出现Server500错误,javascript,php,Javascript,Php,我正在创建一个程序,从文本文件中读取并显示一个随机单词和单词定义。每当我使用mamp运行web页面时,当使用php时,就会出现server500错误 这是我的Javascript function fetchTerm() { var myXMLRequest = new XMLHttpRequest(); myXMLRequest.open("GET", "play.php", true); myXMLRequest.send(); } function createR

我正在创建一个程序,从文本文件中读取并显示一个随机单词和单词定义。每当我使用mamp运行web页面时,当使用php时,就会出现server500错误

这是我的Javascript

function fetchTerm() {


   var myXMLRequest = new XMLHttpRequest();
   myXMLRequest.open("GET", "play.php", true);
   myXMLRequest.send();

}

function createRandomWordDefin() {

   var json = JSON.parse(this.responseText);

   document.getElementById("defin").innerHTML = json.defintion;
   document.getElementById("word").innerHTML = json.word;
}
这是我的php

<?php
//task 1 open and read the file into array
$line = file("./play.txt");
//task 2 randomly select a term and definition
list($word, $name, $definition)= preg_split("/[\t]/",trim(($line[array_rand($line)]));
//tsk3 create a json object
$json =array(
    "definition"=> $definition,
    "name" => $name,
    "word" => $word
);
//task4 reeturn the json object
header("Contenttype:Application/json");
print(json_encode($json));
?>

数组元素应以逗号分隔
,您应启用错误报告以了解错误的位置

$json =array(
    "definition"=> $definition,
    "name" => $name,
    "word" => $wordm
);

这不是问题我的实际代码没有这个错误