I am trying to send over a string from PHP to a variable in JSON. But each time the page loads I get a 404 resource error for some reason. I don't understand what is happening and why I keep getting this error. I get the error after the webpage runs through the script part of the code. The way I check this out was using the dev kit in google chrome.
I'm running PHP through Microsoft IIS.
GettingFileInfo.php
<?php
//Calls the getFileInfoMainFunction
getFileInfoMainFunction();
//Function : sscaddir
//Parameters : $dir
//Returns : array
//Description : This function takes an array where we get rid of the dots
function sscandir($dir)
{
return array_values(array_diff(scandir($dir),array('..','.')));
}
function getFileInfoMainFunction(){
//variables
$implodedFilesEqual;
$toJson;
//C:\localwebiste\holmes-e-joesph-r
$fileDirectory=dirname(__FILE__);
//now we are in the MyFilesDirectory
$fileDirectory.="\MyFiles";
//store all the files in the filedirectory in an array
$files=sscandir($fileDirectory);
//The '|' delimter
//This is the string that we will send too the client side code.
$implodedFilesEqual=implode("|",$files);
//For testing purpose
print_r($files);
$toJson=json_encode($implodedFilesEqual);
echo ($implodedFilesEqual);
//Test.txt|test3.txt
}
?>
HTML page:
<html>
<head>
<title>Starting Page</title>
<link rel="stylesheet" href="StartPage.css" media="screen">
<script src="https://ajax.googleeapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="jQuery.js"></script>
</head>
<body id="theTextEditorsBody">
<p id="demo"></p>
<h1>Text Editor</h1>
<hr>
<textarea id="textArea"></textarea>
<br>
<select>
<option>textFile1</option>
<option>textFile2</option>
<option>textFile3</option>
</select>
<p id="hello"></p>
</body>
jQuery.js:
const xmlhttp=new XMLHttpRequest();
xmlhttp.onload=function(){
const myObj=JSON.parse(this.responseText);
document.getElementById("demo").innerHTML=myObj.name;
}
xmlhttp.open("POST","GettingFileInfo.php");
xmlhttp.send();