Created
October 2, 2017 14:06
-
-
Save leylaKapi/306cd6f173acd72cbe3b3649d025d9e3 to your computer and use it in GitHub Desktop.
Spining loader ajax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function spining_calculator(target_div) { | |
if (target_div == ''){ | |
var indicator = '<table id="indicator" style="width:100%;height:100%;" class="ajax_loading indicator_small"><tr><th style="text-align:center"><img src="/images/indicator-small.gif" /></th></tr></table>'; | |
$('body').prepend(indicator); | |
} else { | |
var width = $(target_div).width(); | |
var height = $(target_div).height(); | |
var indicator = '<table id="indicator" style="width:'+width+'px; height:'+height+'px;" class="ajax_loading indicator_small"><tr><th style="text-align:center"><img src="/images/indicator-small.gif" /></th></tr></table>'; | |
$(target_div).prepend(indicator); | |
} | |
} | |
$('#product_list .caption .added_to_cart').click(function() { | |
spining_calculator($('#product_list')); | |
var price_id, product_id, quantity; | |
quantity = $(this).prev().val(); | |
product_id = $(this).attr('data-product-id'); | |
price_id = $(this).attr('data-price-id'); | |
$.ajax({ | |
type: 'POST', | |
url: '/order_items', | |
data: { | |
quantity: quantity, | |
product_id: product_id, | |
price_id: price_id | |
}, | |
success: function() { | |
alert('Add to cart'); | |
}, | |
error: function() { | |
alert('Try again'); | |
}, | |
complete: function() { | |
$('#indicator').remove(); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment