I’m trying to display an image (.gif) for “page loading” in html page until the output from my_script.py gets displayed, and I’ve no idea how to do that. This is what I’ve got so far. Many thanks in advance.
HTML:
<div id="loading">
<p><img src="./images/loading.gif" /> Please Wait</p>
</div>
<form action="./cgi-bin/my_script.py" method="post" enctype="multipart/form-data" name="fname">
<input type="submit" id="submit" value="Submit" />
</form>
js:
$(document).ready(function() {
$("form").submit(function() {
showLoading();
$('#content').load('./cgi-bin/my_script.py', null, showResponse);
});
function showResponse() {
hideLoading();
}
function showLoading() {
$("#loading").show();
}
function hideLoading() {
$("#loading").hide();
}
});
Your script can be simplified to this:
The revisions I made are:
e.preventDefault()to prevent default form submission if user has Javascript enabled.#contentselector, change the internal ofhtml()to what you want to be displayed. This will cause the initial content to be your loading message, then it will either be replaced by what’s returned by.loadon success, or you’ll have to explicitly tell it what to be replaced with if it’s an error.Fiddle
http://jsfiddle.net/8pgrD/