hello Whenever I click on the button that says "Get External Content" I get a javascript alert that says "Not Found" (this is the error's status text).
Why can it not find the text file I am trying to load via ajax?
This is my folder hierarchy:
--public_html
--app
--ajaxTestHome.php
--ajaxTestText.txt
And this is the file I am trying to load (via ajax) the text file into.
//ajaxTestHome.php
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#ajax").click(function(){
$.ajax(
{
url:"/app/ajaxTestText.txt",
success:function(result){
$("#div1").html(result);
},
error: function(abc) {
alert(abc.statusText);
},
cache: false
}
);
});
});
</script>
</head>
<body>
<div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div>
<button id="ajax">Get External Content</button>
</body>
</html>
EDIT: I had a typo in the question. the file is called "ajaxTestText.txt" not "ajaxTestTest.txt"
You shouldn't need the /app/
in the url.
Also your file is called ajaxTestTest.txt
and the url you are calling is ajaxTestText.txt
they have different names
The URL parameter is incorrect:
$(document).ready(function(){
$("#ajax").click(function(){
$.ajax(
{
url:"ajaxTestText.txt",
success:function(result){
$("#div1").html(result);
},
error: function(abc) {
alert(abc.statusText);
},
cache: false
}
);
});
});
I found the solution.
The problem did not have anything to do with it being in the wrong directory or me referencing the file with or without the "/" or the "/app/" or "app/".
Rather I changed the extension from .txt to .html. I was accessing this from a server I was FTPing to, and I guess the server won't correctly let you see/access the contents of a txt file but will an HTML? If you happen to know, please enlighten me.