Skip to content

Instantly share code, notes, and snippets.

@gmilby
Created July 3, 2013 13:27
Show Gist options
  • Save gmilby/5917838 to your computer and use it in GitHub Desktop.
Save gmilby/5917838 to your computer and use it in GitHub Desktop.
jquery / ajax spinner = david walsh blog
<select class="ajax">
<option value="">-- Select a Site--</option>
<option value="David Walsh Blog">David Walsh Blog</option>
<option value="Script & Style">Script & Style</option>
<option value="Band Website Template">Band Website Template</option>
</select>
<br /><br />
<input type="text" id="my-text" class="ajax" />
$(document).ready(function() {
//create image
$('<img src="move-spinner.gif" id="spinner" />').css('position','absolute').hide().appendTo('body');
//for every field change
$('.ajax').change(function() {
//get element position
var position = $(this).offset();
//position image
$('#spinner').css({ top: position.top , left: position.left + $(this).width() + 30 }).fadeIn();
//ajax
$.post('<?php echo $_SERVER['REQUEST_URI']; ?>',{
ajax:1,
value: $(this).val()
},function() {
$('#spinner').fadeOut();
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment