简体   繁体   English

使用jquery / ajax时脚本无法加载

[英]script does not load while using jquery/ajax

I'm trying to add through ajax/jquery a script into a div seconds after the page has loaded. 我正在尝试通过ajax / jquery在页面加载后几秒钟内将脚本添加到div中。 The script itself is from a CPM network and loads a banner. 该脚本本身来自CPM网络,并加载横幅。

When I load it right when the page loads, the script is loaded, but if I add it through ajax, the script stays like this: 当我在页面加载时正确加载它时,脚本就会加载,但是如果我通过ajax添加它,脚本将保持如下所示:

<script>content here...<script>

I get the following information after loading it by ajax: "Resource interpreted as Script but transferred with MIME type text/html" 我通过ajax加载后得到以下信息:“资源解释为脚本,但以MIME类型text / html传输”

I searched for some solutions but can't find one that works. 我搜索了一些解决方案,但找不到可行的解决方案。

Here is the ajax call: 这是ajax调用:

function showAds(){
        $.ajax({
            url:"pub-horizontal.php",
            type:"POST",
            async: false,
            data: {link:link},
            success:function(result){
                $("#p1").html(result);
            }
        });
    }

Here is pub-horizontal.php file 这是pub-horizo​​ntal.php文件

<div class="col-xs-12">
<div id="pub-horizontal" class="pub-horizontal">
    <?php

        $url = $_POST['link'];

        if(!strpos($url,"article")){
            include("****-horizontal.php");
        }else{
            include("cpmfun-horizontal.php");
        }



    ?>
</div>
</div>

I tried to output something into the console using the script and it worked! 我试图使用脚本将某些内容输出到控制台中,并且可以正常工作! Seems like that the problem is with the script of the CPM network that does not load after the document has loaded... 似乎问题出在文档加载后无法加载的CPM网络脚本...

Thanks in advance. 提前致谢。

Try adding header("content-type: application/javascript"); 尝试添加header("content-type: application/javascript");

at the top of the php file 在php文件的顶部

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM