Insert call to external PHP script tag into element using jQuery

67 views Asked by At

I am in need of inserting the following into the footer using jQuery. It generates a small ad banner.

<script src="http://14489-001.pod1.us01.hst.inclickadserver.com/ads/ads.php?t=MTAwMjsxO2hvcml6b250YWwubGVhZGVyYm9hcmQ=&index=1"></script>

I tried the following to no avail:

    var s = document.createElement("script");
    s.src = "http://14489-001.pod1.us01.hst.inclickadserver.com/ads/ads.php?t=MTAwMjsxO2hvcml6b250YWwubGVhZGVyYm9hcmQ=&index=1";
    $(".copyright-container").prepend(s);

as well as things like:

$("<script src='http://14489-001.pod1.us01.hst.inclickadserver.com/ads/ads.php?t=MTAwMjsxO2hvcml6b250YWwubGVhZGVyYm9hcmQ=&index=1'></scr" + "ipt>").insertBefore('.copyright-container');

I'm getting no errors in Chrome's console, but nothing appears. The ad appears if I just paste the script tag into the body of any page on the site.

1

There are 1 answers

8
RightClick On BEST ANSWER

Depending on how you load the js, it might not evaluate. Jquery has a getScript function, although using it for cross site js files might be difficult. Here is some sample code.

$.getScript( "ajax/test.js", function( data, textStatus, jqxhr ) {
  console.log( data ); // Data returned
  console.log( textStatus ); // Success
  console.log( jqxhr.status ); // 200
  console.log( "Load was performed." );
});