None of the answers I found on the Internet satisfied me while I looked at the solution. Not even that. After reading a lot more about the jQuery API documentation, I found something really interesting . As described on this web page, you can bind an event in which it will be executed after the ajax request is executed. The fact is that it is not just like this; Since I was doing my own tests using the example provided in the API documentation, I could not get it to work. It seems that my jQuery dialog did not exist in the context of the βfutureβ.
This led me to this page , the description of which was: Attach an event handler for all elements that match the current selector, now and in the future. Finding this leads me to create a function like this:
$(document).live("ajaxStop", function (e) { $(".myDiagDiv").dialog("option", "position", "center"); });
And voila! It works great! After executing the ajax request, the position property changes and adapts to the contents of the div and its size!
Hope this helps people in the future!
EDIT: you can use the function .on () instead of .live (). Since I wrote my answer, it seems that the ".live ()" function has been removed in jQuery version 1.9 and replaced with a new one. A more suitable solution for jQuery> = 1.9 users would look something like this:
$(document).on("ajaxStop", function (e) { $(".myDiagDiv").dialog("option", "position", "center"); });
Davewut
source share