Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery UI draggable doesn't work with AJAX

I have a simple D&D script as you can see here:

http://demo.superdit.com/jquery/dragdrop_cart/

Now its working Great until Im trying to add the products with AJAX (After the page loaded)

Here is the AJAX call (Regular AJAX)

$.ajax({
              url: "Search.php",
              dataType: 'json',
              type: 'GET',
              data: "ebayq="+value,
              success: function(data){
                globalRequest = 0;
                resultContainer2.fadeOut('fast', function() {
                    resultContainer2.html('');

              var html2 = [];


    for (var i = 0; i < items.length; ++i)  
  {

html2 += '<label class="title"><a href="'+viewitem+'" target="_blank">'+title+'</a></label>';html2 += '<img src="'+pic+'">';
        html2 += ' <label class="price">New Price: '+myprice+'</label>';
        html2 += '</div>';
        resultContainer2.append(html2);

  }

i guess because this elements are loaded after the page load and it doesn't recognize them as a draggable items..

is there Any way to make this AJAX items draggable??

Thank you very much!

like image 678
Eran Levi Avatar asked Oct 06 '22 04:10

Eran Levi


1 Answers

Run $('your-selector').draggable() again, in your AJAX success method.

Unless you can find a way to make Jquery.on or Jquery.live to work with JqueryUI.Draggable.

like image 174
MichaelS Avatar answered Oct 10 '22 03:10

MichaelS