Saturday, March 29, 2014

Cannot call method 'removeChild' of null on beforeStop for sortable in jquery by Sachin Gevariya

I am using jQuery sortable for drag and drop an item from one place to another place and I am using start and stop for event start and stop.

But I am using beforeStop for avoid some movements of item from one place to anther place but its show me an error like that: Cannot call method 'removeChild' of null

Here I am using this one:
   beforeStop: function(event, ui){ 
            var firstNameClass = ui.item.firstChild.className;
           
            if (firstNameClass == "firstName"){
                $(this).sortable('cancel');
            }
        }

For resolve this error remove this code from beforeStop() to Stop() and that's working for me!!!!!


Use data from success of AJAX on next step

If you are using ajax request for get and post data then you are also know about thier scopes but I would like to tell you one scope which is very userful when you need data from ajax and then you need to use it after ajax.

I meant that we can use data outside of ajax when we get response from AJAX.

so its cool!!!

We can use "async" scope for this purpose.

We can maintain orders by async. Otherwise AJAX will move on next orderand in this example if we not using async:false then we are not able to use jsonData after ajax response.

Here is one example for use this scope so you can also look at it!!!
function findData(id) {     
      var data;  
      $.ajax({         
          url: this.urlRoot + "/" + id + "/endData", 
          async: false,
          dataType: "json",           
                     success: function(jsonData){                
                       data = jsonData;     
                 } 
             }); 
             var used_Data = jsonData;      
             console.log(used_data);
       }