Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery UI draggable doesn't inject when using an ajax content refresh
    primarykey
    data
    text
    <p>Basically I setup a page with a few draggable elements, it worked fine.</p> <p>I've just added an ajax content refresh that refreshes the div, the elements are inside, every 10 seconds.</p> <p>After doing this the draggable function no longer works.</p> <p>I believe this is because the elements that are getting refreshed are on a separate page, and then loaded into the index with ajax.</p> <p>How can I resolve this issue?</p> <p>Thank you</p> <hr> <p><strong>Basic HTML (nothing special here)</strong></p> <pre><code>&lt;div id="notes"&gt; &lt;!--Notes Load Here--&gt; &lt;/div&gt; &lt;div id="loading"&gt; Loading.. &lt;/div&gt; &lt;script src="http://code.jquery.com/jquery-latest.min.js"&gt;&lt;/script&gt; &lt;script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"&gt;&lt;/script&gt; &lt;script src="js/scripts.js"&gt;&lt;/script&gt; </code></pre> <p><strong>Scripts.js (inc. Document ready)</strong></p> <pre><code>/* Draggable functionaility */ var a = 3; $('.postit').draggable( { start: function(){ $(this).css("z-index", a++); }, stop: function(){ var offset = $(this).offset(); var xPos = offset.left; var yPos = offset.top; var pid = $(this).attr('id'); var datastring = 'xpos=' + xPos + ' ypos=' + yPos + ' id=' + pid; $.ajax({ type: "POST", url: "savepositions.php", datatype: "text", data: {positions: datastring} }); } }); $('.postit').click(function(){ $(this).addClass('top').removeClass('bottom'); $(this).siblings().removeClass('top').addClass('bottom'); $(this).css("z-index", a++); }); /* Auto Refresh */ $.ajaxSetup( { cache: false, beforeSend: function() { $('#notes').hide(); $('#loading').show(); }, complete: function() { $('#loading').hide(); $('#notes').show(); }, success: function() { $('#loading').hide(); $('#notes').show(); } }); var $container = $("#notes"); $container.load("notes.php"); var refreshId = setInterval(function() { $container.load('notes.php'); }, 10000); </code></pre> <p><strong>Notes.php</strong> For all intents and purposes, this just contains a div with class="postbit"</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload