与脚本一起异步加载网页的一部分



正如我的标题所说,我必须加载一个ID为"data"的div,并且里面有脚本标签。我可以使用jquery,但不能使用它的$.load函数,因为它去除了脚本标签。

我也用过 $("#container").load("setting.php #data");现在JavaScript运行良好,但显示整个网页。请任何人帮助我。

注意:嘿,我没有加载两次数据。我的 #containerdiv要么是空白的,要么包含任何其他网页,并且在加载时我确保容器是空的。

我假设您在此处加载数据两次,如果是这种情况,那么您可能希望在.load()函数中重新检查。内容已加载,您再次尝试将其插入代码的第二行。试试这个:

$( "#container").load( "setting.php#data",function( response, status, xhr ) {
if ( status == "error" ) {
   var msg = "There was an error: ";
   $( "#error" ).html( msg + xhr.status + " " + xhr.statusText );
 }
});

我通过长时间的搜索找到了答案。其代码是这里what代表网址

    $.post(what+" #data", function(html) {
 var markup = $($.trim(html));
 markup=markup.find('#data');
 $('#working_area').html(markup);
 window.history.pushState(window.location.pathname,"",what)});

最新更新