This is my code and im trying to load html from demo_test.txt into it, but it won't work no matter what I try, ive tried changing it from txt to html as well and it still won't load. The other ajax command such as appending the text works correctly its the load line which won't work?
<head>
<title>Flask AJAX Demo</title>
<!--<link rel=stylesheet type=text/css href="{{ url_for('static', filename='style2.css') }}"> -->
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<script type=text/javascript
src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type=text/javascript>
var $SCRIPT_ROOT = {{ request.script_root|tojson|safe }};
</script>
<script type=text/javascript>
$(function() {
$("#submitBtn").click(function() {
$('#div1').load('dem_test.txt');
$.ajax({
type: "GET",
url: $SCRIPT_ROOT + "/echo/",
contentType: "application/json; charset=utf-8",
data: { echoValue: $('input[name="echoText"]').val() },
success: function(data) {
$('#echoResult').append("<br>");
$('#echoResult').append(data.value);
}
});
});
});
</script>
<strong>Enter a value to echo back:</strong>
<input type='text' size='10' id='echoText' name='echoText'>
<button type='button' id='submitBtn' name='submitBtn'>Submit via AJAX</button><br /><br />
<strong><div id='echoResult'></div></strong>
<div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div>
This is what is in the demo_test.txt, this wont work if it is html either
<h2>jQuery and AJAX is FUN!!!</h2>
<p id="p1">This is some text in a paragraph.</p>
EDIT:
I changed my load to this:
$('#div1').load('dem_test.txt', function(response, status, xhr) {
if ( status == "error" ) {
alert("Error occured: " + xhr.status + " " + xhr.statusText );
} else {
alert("Text loaded!");
}
});
But I get Error occured: 404 error , but the dem_test.txt file is in the same folder as the html file?
EDIT 2
I have tried this exact example as well found here: .load() method in jquery give me 404 - Not Found error BUT it won't work like his didnt either, what should the file location be?