I'm creating a program that reads from a text file and displays a random word and the words definition. whenever I run the web page with mamp, I get a server 500 error when the php is used.
here is my 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;
}
here is my 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));
?>