javascript - jQuery $.each()-problem -


im is building a wordpress plugin and I have a function where I import the image, $ .ee () Is done with - the loop which calls an .load () - each recursive function. Downloading load-function page load-function call image and returns a number. The number is imported into a duration element Source and destination ARAI is being imported from the light giants of hidden UL.

In this way, the user is imported from zero to the total number of images from the countdown. You can do this with my jQuery code below:

  jQuery (document) .ready (function ($) {$ ('# mrc_imp_img'). Click (function () {var dstA = []; Each (function ($ ("# mrc_dst li") {SrcA.push ($ (this) .text ()) $ .each (srcA, function (i, v) {$ ('# mrc_imgimport Span.fc '). Load (' / wp-content / Plugins / myplugin / imp.php? Num = '+ i +' & amp; dst = '+ dstA [i] +' & src = '+ srcA [i ]};});});});  

This works very well, but sometimes it seems that the load function is not updating DOM fast It should be because sometimes the numbers It has been updated with the duration, it is less than the previous one almost every number is finally replaced by the last number. I can stop this from happening and when I'm ready for a $$ .each-loop How can I hide '#mrc_imp_img'?

The AJAX call that has been previously called, He is not guaranteed to finish first, so small numbers can overwrite bigger. One solution is to increase the counters on each successful call:

  jQuery (function ($) {$ ('# mrc_imp_img'). (Function () {var dstList = $ ("# Mrc_dst li "); var sqlist = $ (" # mrc_src li "); dstList.each (function (i) {var dst = $ (this) .text (); var sRC = sslist [i] .text (); $ .post ('/ wp-content / plugins / myplugin / imp.php? Num =' + i + 'and dst =' + dst + 'and src =' + src, function () {$ ('# mrc_imgimport Span .fc '). Text ($ (' # mrc_imgimport span.fc '). Text () + 1);}}}}}}};});  

(unnecessary The code has been changed to avoid array operation, the current call has been changed to use the shorthand Is replaced AJAX call to use the post, which should be used for the operation that the state change.)


Comments