View Full Version : How is Ext code handle on a Ajax response?

20 Feb 2008, 8:02 AM
I'm making an Ajax request and replacing a div with the response. The response contains code fragments inside Ext.onReady calls. My code is not getting called and I understand it is because Ext is already ready. How do I get Ext.onReady() in the response to work?

20 Feb 2008, 8:12 AM
You should use Element.load() to load the content and specify scripts:true in the config.

This will load the DOM first and execute any contained scripts (both linked and inline) AFTER that (so there is no need for Ext.onReady).

20 Feb 2008, 8:24 AM
In my case the same fragments of code are also used in non-Ajax requests so I have Ext.onReady() blocks. How can I make it work in both cases? I am using Element.load() with scripts: true. Is there a way to clear the existing onReady() calls and then fire the ready event as the last line in the Ajax fragment?

20 Feb 2008, 8:26 AM
Would using an IFRAME (I recommend ManagerIframePanel) be an option?

20 Feb 2008, 8:30 AM
IFRAME: Not sure. Unfortunately I have a release and I cannot experiment too much. What is the ManagerIFramePanel? Could not find it in the docs. Is it a user extension?

20 Feb 2008, 12:04 PM
Yes, it's probably the most used user extension (you can find it here (http://extjs.com/forum/showthread.php?t=16590)).

21 Feb 2008, 5:48 AM
Actually I got around to making it work in a very simple way. On the server side I can distinguish between Ajax and Non-Ajax requests (using a http parameter). Then I simply spit out "Ext.onReady() {" and "});" pairs for non-Ajax requests and "new function() {" / "}" for Ajax requests. The rest of the code remains the same.

We use a templating engine on the backend so I simply have functions called extReadyBegin() and extReadyEnd() which the entire code calls and they decide what to spit out. Hope this helps someone.

21 Feb 2008, 5:50 AM
BTW, Just out of curiosity is it not possible to have Ext.onReady() itself know that it is ready and make the call right away? I'm sure Jack had a good reason for not doing that. What is it?