jquery-load

Using jQuery load with promises

主宰稳场 提交于 2019-11-27 02:09:52
问题 I'm still trying to wrap my head around deferred and what not, so with this in mind I have a question on how to do the following. My team and I have 3 separate .load() methods that each go grab a specific template and append that to the same container. Each load takes a different amount of time as you might think, so when the content loads, it loads in a 'stair step' fashion (1, then 2, then 3). I'd like to make use of deferred objects and wait until they are all done, then append them at the

How to cancel a jquery.load()?

↘锁芯ラ 提交于 2019-11-27 01:44:23
I'd like to cancel a .load() operation, when the load() does not return in 5 seconds. If it's so I show an error message like 'sorry, no picture loaded'. What I have is... ...the timeout handling: jQuery.fn.idle = function(time, postFunction){ var i = $(this); i.queue(function(){ setTimeout(function(){ i.dequeue(); postFunction(); }, time); }); return $(this); }; ... initializing of the error message timeout: var hasImage = false; $('#errorMessage') .idle(5000, function() { if(!hasImage) { // 1. cancel .load() // 2. show error message } }); ... the image loading: $('#myImage') .attr('src', '

How to cancel a jquery.load()?

◇◆丶佛笑我妖孽 提交于 2019-11-26 17:28:33
问题 I'd like to cancel a .load() operation, when the load() does not return in 5 seconds. If it's so I show an error message like 'sorry, no picture loaded'. What I have is... ...the timeout handling: jQuery.fn.idle = function(time, postFunction){ var i = $(this); i.queue(function(){ setTimeout(function(){ i.dequeue(); postFunction(); }, time); }); return $(this); }; ... initializing of the error message timeout: var hasImage = false; $('#errorMessage') .idle(5000, function() { if(!hasImage) { //

Can jQuery .load append instead of replace?

帅比萌擦擦* 提交于 2019-11-26 16:26:52
问题 I have a WordPress install and I'm trying to use jQuery to create a Load More effect. I'm having some trouble using the basic .load feature for page fragments. I don't mind using .get as I saw some threads here regarding that as a better solution. Here's my page URL structure and the contents: First Page: http://example.com/page/1/ The HTML: <div id="articles"> <div class="story">blah blah blah</div> <div class="story">blah blah blah</div> <div class="story">blah blah blah</div> <div class=

Asynchronously load images with jQuery

喜夏-厌秋 提交于 2019-11-25 22:46:10
问题 I want to load external images on my page asynchronously using jQuery and I have tried the following: $.ajax({ url: \"http://somedomain.com/image.jpg\", timeout:5000, success: function() { }, error: function(r,x) { } }); But it always returns error, is it even possible to load image like this? I tried to use .load method and it works but I have no idea how I can set timeout if the image is not available (404). How can I do this? 回答1: No need for ajax. You can create a new image element, set

jQuery callback on image load (even when the image is cached)

社会主义新天地 提交于 2019-11-25 21:43:36
问题 I want to do: $(\"img\").bind(\'load\', function() { // do stuff }); But the load event doesn\'t fire when the image is loaded from cache. The jQuery docs suggest a plugin to fix this, but it doesn\'t work 回答1: If the src is already set, then the event is firing in the cached case, before you even get the event handler bound. To fix this, you can loop through checking and triggering the event based off .complete , like this: $("img").one("load", function() { // do stuff }).each(function() {