开发者

Running jQuery code retrieved from ajax request, what should I remember to delete?

开发者 https://www.devze.com 2023-01-24 15:30 出处:网络
I understand that it\'s possible (and I have done it) to return javascript and jQuery code (which of course is javascript... hehe) when doing a jQueryajax request and running it once it reaches the br

I understand that it's possible (and I have done it) to return javascript and jQuery code (which of course is javascript... hehe) when doing a jQuery ajax request and running it once it reaches the browser.

What I'm wondering is if I return data, let's say a form, that I present in a dialogcontainer. What should I delete myself once that container is closed by the user and what does jQuery understand by itself to delete.

My ide开发者_运维百科a is to build a page that require very little page reloads and once a user clicks on a button I present them with a form or some other content fetched from the server. Alongside that content the javascript required by that content should also be retrieved. But if the dialog is closet I don't want tons of javascript to be left eating memory. Any way around that?


You could unbind the click event that does the ajax call. If nothing is going to change if they open the dialog again, then this should be fine. While you unbind it you could then change it more a toggle type of thing (Show/Hide), since the javascript and HTML should already be set now.

But it really depends on what you are trying to do. The ajax call will only happen once they click it. It's not going to continually refresh unless you want to. So there should be nothing in the background running except for binding events like click, which is ok.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号