Ajax replaces a bunch of HTML, how to update the associated jQuery actions like Drag And Drop?

StackOverflow https://stackoverflow.com/questions/3358674

  •  03-10-2020
  •  | 
  •  

Question

So I've finally figured out a system for refreshing portions of the screen using Ajax, Taconite, and jQuery within Django, sortof like Ruby on Rails partials.

I was pleased, but unfortunately, the code associated with clicking and drag and dropping is not executing.

I'm replacing the html inside divs.

How can I keep my code modular (separate pieces of content in refreshable divs), yet make sure my jQuery draggables, droppables, clickables, hoverables, etc get reactivated?

Thanks!

Update

I setup a $(document).ready(callasetupfunction) [as recommended below] and it seems to be getting called after each AJAX call. Is that the expected behavior for .ready?

I've also noticed that i can bind multiple functions to the $(document).ready(). So I can do that (in other words it's a lot better than setting the onload huh?)

Was it helpful?

Solution

Without seeing your code, the only advice I can think of is to pull the portions of your code that call .draggable, etc into a function (probably one that takes a selector), and add that function as a callback after your ajax call completes.

If that doesn't make sense, or is not doable for some reason, and you can put up some working example code that demonstrates the problem, I or someone else can help you find a solution.

Edit: It looks like you might need to stick the call to the above javascript function in a script tag in your response, if you're set on using taconite.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top