views:

238

answers:

2

Hi, i have discovered quite an odd behaviour of jquery. I have two lists here, where i drag and drop li-elements from one to another, the current sortings is being saved by ajax-mysql. Now this afternoon i noticed that sometimes, just sometimes the position of the last dropped item wasnt saved properly, it was saved as "0" when it should be for example 4 or 5. Took me some hours to find out that this behaviour is in direct relation to the alert, that is triggered after a drop of an item:

alert(data);       <---- data is the current sorting of the ids

If i remove this line, then the above described odd behaviour of the script appears. Maybe someone has experienced something like this before and can share some advise?

greets, Maschek

edit: This is the function, that contains the alert:

            $(function() {

             $("#sortable2").sortable({

                  items: \'li:not(.col_header)\',
            connectWith: \'#sortable2, #sortable1, #sortable1b, #sortable1c\',   
            helper: \'clone\',
            placeholder: \'empfaenger-highlight\',
         revert: \'invalid\',
         update: function() {

              var data = $(this).sortable("serialize") + \'&user='.$user.'\';

              alert(data);
              var order = $(this).sortable("serialize") + 
              \'&action=updateList&user='.$user.'\'; 
             $.post("index.php?eID=moveitems", order, 
             function(theResponse){

                   $("#response").html(theResponse);
                   $("#response").slideDown(\'slow\');
                   slideout(); 

                 }); 

               } 

          }).disableSelection();
A: 

You are right, probably more easy to read from the output-code. The script:

 <script type="text/javascript">
           $(document).ready(
           function () {
                function slideout(){

                setTimeout(function(){

                     $("#sortable3 .provider, #sortable3 .empfaenger, #response").fadeOut("slow", function () {

               });

           }, 2000);}


           $(function() {

                $("#sortable2").sortable({

                     items: 'li:not(.col_header)',
                    connectWith: '#sortable2, #sortable1, #sortable1b, #sortable1c',            
                    helper: 'clone',
                    placeholder: 'empfaenger-highlight',
                    revert: 'invalid',
                    update: function() {

      var data = $(this).sortable("serialize") + '&feuser=14';

      alert(data);
      var order = $(this).sortable("serialize") + 
      '&action=updateList&feuser=14'; 
      $.post("index.php?eID=moveitems", order, 
      function(theResponse){

                               $("#response").html(theResponse);
                               $("#response").slideDown('slow');
                               slideout();  

                          }); 

                     }  

                }).disableSelection();
maschek
can someone please give me a hint?
maschek
A: 

I tried to use a callback, to ensure the variable being loaded completely:

                    $(function() {

                     $("#sortable2").sortable({

                          items: \'li:not(.col_header)\',
                          connectWith: \'#sortable2, #sortable1, #sortable1b, #sortable1c\',            
                          helper: \'clone\',
                          placeholder: \'empfaenger-highlight\',
                          revert: \'invalid\',
                          update: function() {



                          var data = $(this).sortable("serialize");

                               function doSomething(data) {

                          };

                               //alert(data);
                               var order = data + \'&action=updateList&feuser='.$user.'\'; 

                               $.post("index.php?eID=moveitems", order,  function(theResponse){

                          }); 

                     }  

                }).disableSelection();

But the descriped miss-behaviour still occurs. Can someone tell me, if the use of this additional callback-function is the right approach? Or how else would i have to handle this, to ensure properly variable? thanks for your advises...

maschek