0

I'm trying to add through ajax/jquery a script into a div seconds after the page has loaded. The script itself is from a CPM network and loads a banner.

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:

<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"

I searched for some solutions but can't find one that works.

Here is the ajax call:

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

<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...

Thanks in advance.

Th3lmuu90
  • 1,717
  • 2
  • 15
  • 18

1 Answers1

0

Try adding header("content-type: application/javascript");

at the top of the php file

andrew
  • 9,313
  • 7
  • 30
  • 61
  • I get the following error: Warning: Cannot modify header information - headers already sent by (output started at ************article.php:3) in ***********article.php on line 4 AND I know that I need to add it right after the – Th3lmuu90 Nov 29 '13 at 18:22
  • @Th3lmuu90 Would `ob_start()` help with that? [Ref1](http://stackoverflow.com/questions/1450990/why-ob-start-must-come-ahead-of-session-start-to-work-in-php) [Ref2](http://stackoverflow.com/questions/3122343/php-ob-start-and-session-start-question) – cssyphus Nov 29 '13 at 18:26
  • perhaps try with jquery load instead `$(#p1).load('pub-horizontal.php',{link:link});` – andrew Nov 29 '13 at 18:29
  • @gibberish not really... I added ob_start after and before header and the error continues... and I have session_start after the header and ob_start() – Th3lmuu90 Nov 29 '13 at 18:32
  • @andrew not even with jquery load. I always get the following information: Resource interpreted as Script but transferred with MIME type text/html: – Th3lmuu90 Nov 29 '13 at 18:34