Javascript 为什么我的php代码会出现Server500错误
我正在创建一个程序,从文本文件中读取并显示一个随机单词和单词定义。每当我使用mamp运行web页面时,当使用php时,就会出现server500错误 这是我的JavascriptJavascript 为什么我的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
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
);
这不是问题我的实际代码没有这个错误