Reputation: 1309
I am trying to add a loading gif to some jquery script. I thought I might use this plugin which has worked before but I am trying to figure out why it is not firing when I submit a form. Have I got it in the correct place?
<script>
$(document).ready(function() {
$('#post_data').submit(function() {
//I've placed the plugin here
$('#spinner').pleaseWait();
$.ajax({
url: 'process.php',
type: 'POST',
dataType: 'html',
data: $(this).serialize(),
success: function(newContent) {
$('#mytable').prepend('<tr>' + newContent + '</tr>');
$("form").trigger("reset");
}
});
return false;
});
});
The div where I want it to appear.
<div class="center-block" id="spinner"></div>
Upvotes: 1
Views: 900
Reputation: 429
Did a fiddle for you: https://jsfiddle.net/2Lazd0ez/
Inserted this line:
$('#post_data').submit(function(e) {
e.preventDefault();
});
The reason being not using preventDefault() and actually submitting the form serverside, instead of through jQuery.
Upvotes: 1
Reputation: 753
Reasons :
Give some width height to spinner div. Try customize the spinner as given in the plug-in. Load scripts at end of body both jQuery after that loader plug-in. Just try with only spinner plug-in without ajax. Add beforesend property in ajax and in that method load the spinner and stop at ajax complete property 😉
Upvotes: 2