I've been struggling with this error for a couple of days now. Searched stackoverflow and other web sources but so far no luck.
The code is fairly simple. I have a test.html file which calls a saveFile.php. However, I have two problems. 1) In Firefox, I keep getting a "no element found" error. Don't see this problem in Chrome. 2) Even though saveFile.php seems to be getting called, it does not write a file as it should. This is the case with both browsers and I really need to be able to write to a file.
This is the test.html file:
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>IIDS: Basic Boilerplate</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
hello world
<script src="../components/jquery/jquery.js"></script>
<script type="text/javascript">
$.ajax({
type: "POST",
url: "saveFile.php",
//url: "http://localhost/~usesr1/mywork/saveFile.php",
//dataType: "json",
data: 'test',
success:function(text) {
console.log(text);
},
error: function(xhr, status) {
alert("unable to save data");
},
});
</script>
</body>
</html>
This is the saveFile.php:
<?php
$tdata = "hello world this is a test";
$testf = fopen('hello123', 'w+');
fwrite($testf, $tdata);
fclose($testf);
echo "yes";
// header("Content-Type: text/plain"); Got this from another stackoverflow question, but this didn't fix the problem.
exit();
?>
Both files are in the same directory under ~/public_html. I gave 777 permissions to the directory. This is a machine running Ubuntu 14.04.
In saveFile.php, tried "GET" instead of "POST" but no luck again.
I'm stuck and any help would be greatly appreciated. Thanks.
EDIT: This question is not a duplicate of the one linked in the comments. The main difference is that I am not able to get my php to write to a file. I don't necessarily care about the "no element found" error as long as the php script is able to write to file. I only decided to include that error in this post because I thought it might be relevant to my real problem.
<?phptagerror_reporting(E_ALL); ini_set('display_errors', 1);header('Content-Type: text/plain');and Firefox will not try to parse the response as XML, and there should be no error.