JulianJ JulianJ - 3 months ago 11
jQuery Question

Why is my jquery loader not working?

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>

Answer

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.