删除AJAX加载的内容和脚本 [英] Remove ajax loaded content and script

查看:128
本文介绍了删除AJAX加载的内容和脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道这可能是重复的,但是,

I dont know this may be duplicate but,

我在响应这一号召我发送一些HTML和脚本在我的网站上使用AJAX,现在。

I use ajax in my website, now in response to that call i send some html and script.

然后我替换这些数据与我的一些元素存在于页。

Then I replace that data with some of my element exist in page.

现在,我想要第二个Ajax调用加载从格,所以我已删除HTML内容。话又说回来Ajax调用返回一些其他HTML code和脚本。但有些时候,它是previous脚本和新来的脚本之间的冲突。

Now, I want to make second ajax call so I have removed html content from loaded div. Then again ajax call return some other html code and script. But Some times it is conflict between previous script and newly arrived script.

EX。 第一次回应,我代替HTML,并与一些元素的脚本: $('。ma_right_main)HTML(response.data);

EX. 1st response I replace html and script with some element: $('.ma_right_main').html(response.data);

然后第二个呼叫之前,我删除的内容: $('ma_right_main。)HTML('');

then before 2nd call I remove content: $('.ma_right_main').html('');

第二个反应我替换 HTML 和脚本的一些元素: $('。ma_right_main)HTML(response.data);

2nd response I replace html and script with some element: $('.ma_right_main').html(response.data);

但在更换第二次脚本首次执行返回仍然存在。我想删除它,就像我怎么能删除HTML内容。

but after replace it 2nd time script returned from first time still there in execution. I want to remove it just like how I can remove html content.

推荐答案

我不认为一旦浏览器加载一个脚本,它可以被删除(这并不意味着你不能从DOM中删除,但它仍然存在。)例如,如果你有可变脚本X ,加载网页中的脚本,被加载时,从DOM删除脚本, X 我觉得仍然会被定义。

I don't think once a browser has loaded a script that it can be removed (this doesn't mean you can't remove it from the dom, but it would still exist.) For example if you had a script with variable x, load the page so the script gets loaded, remove the script from the dom, x I think would still be defined.

有办法解决这个不过,如果每一个动态加载的剧本是自己的对象,当卸载,你可以设置对象为null。这是一个解决方案,我碰到了一会儿回来寻找一个类似的解决方案的时候。

There are ways around this though, if each dynamically loaded script was its own object, when "unloading" you could set the object to null. This is a solution I came across a while back when looking for a similar solution.

找到参考我指的是: http://stackoverflow.com/a/1346903/1475461

这篇关于删除AJAX加载的内容和脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆