jquery ajax没有在IE中的标签中添加
我正在通过AJAX加载页面并将其放入DIV中。 包括HTML标签和所有。 没有浏览器似乎担心这一点,除了元素永远不会在IE中加载,但在FF中这样做。
是否可以让的元素加载,或者我是否必须将它们放入体内?
这包括
和 。 但
元素工作正常。 因此我无法使用Ajax加载外部样式表。 有办法吗,还是我必须把它放在体内?
提前致谢。
代码示例:
// page to load // doesn't load /* CSS bla does work*/
如果您在答案中需要,那我正在制作ajax电话。
// ask for the page $.ajax( { url: "Scripts/loader.php", type: "GET", data: data, // created above this call cache: false, success: function (html) { //add the content retrieved from ajax and put it in the #content div $('#content').html(html); // only use fading if opacity is supported if($.support.opacity) { $('#loading').hide(); $('#content').fadeIn(); } } });
你真的应该使用元素加载一个“完整”的网站(用
, and
标签表示。否则它是100%无效的标记。
我的意思是剥离它会是令人讨厌的工作,但是……也许不是那么讨厌:
success: function (html) { //add the content retrieved from ajax and put it in the #content div var stripped = $(html), head = document.getElementsByTagName('head')[0] || document.documentElement; stripped.find('head').contents().each(function(index, node) { if(node.nodeType !== 3) { node.setAttribute('data-insertID', 'foobar'); head.appendChild(node, head.firstChild); } }); $('#content').html(stripped.find('body').contents()); // only use fading if opacity is supported if($.support.opacity) { $('#loading').hide(); $('#content').fadeIn(); } }
删除:
$('head').find('[data-insertID]').remove();
这将从您收到的站点的head section
获取所有节点并将其放入您的actuall网站。 之后它从标签获取所有节点并将它们放入你的div ..应该工作,让我知道:)