bgneal@404: $(document).ready(function() { bgneal@404: $('.dl-button').each(function(n) { bgneal@404: var button = $(this); bgneal@404: var id = button.attr('id'); bgneal@404: var numeric_id = -1; bgneal@404: if (id.match(/dl-(\d+)/)) bgneal@404: { bgneal@404: numeric_id = RegExp.$1; bgneal@404: } bgneal@404: button.click(function() { bgneal@404: button.attr('disabled', 'disabled').val('Getting link, stand by...'); bgneal@404: $.ajax({ bgneal@404: url: '/downloads/request/', bgneal@404: type: 'POST', bgneal@404: data: { id: numeric_id }, bgneal@404: dataType: 'json', bgneal@404: success: function(result) { bgneal@404: var link_id = result.id; bgneal@404: var div = $('#link-' + link_id); bgneal@404: div.hide(); bgneal@1151: div.addClass('success callout'); bgneal@404: div.html( bgneal@404: 'Thank you! Your download is now ready. Click here to download.'); bgneal@404: div.fadeIn(3000); bgneal@404: }, bgneal@404: error: function (xhr, textStatus, ex) { bgneal@404: alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + bgneal@404: xhr.responseText); bgneal@404: } bgneal@404: }); bgneal@404: }); bgneal@404: }); bgneal@404: });