javascript - 无法在php中调用脚本标签

标签 javascript php jquery html

我在下面有这个脚本,它运行良好。当我直接加载 .php 文件时,即使使用外部 javascript 标签,它也能正常工作。

index.html

<div id="content"></div>
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="test.js"></script>

测试.js

$(document).ready(function() {
    $('#content').load('content/index.php')
});

/content/index.php

<?php
    require_once("geoip.inc");
    $gi = geoip_open("GeoIP.dat", GEOIP_STANDARD);
    $country_code = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
    geoip_close($gi);

    if ($country_code == 'RO' ||
        $country_code == 'DO' ||
        $country_code == 'PK' ||
        $country_code == 'MA' ||
        $country_code == 'PE' ||
        $country_code == 'IR' ||
        $country_code == 'DZ' ||
        $country_code == 'RU' ||
        $country_code == 'EG') {
        echo 'country not supported';
    } else {
        echo 'supported';
    }
?>

我的问题是:

当我尝试

echo 'supported';

它运行良好。

但是当我试图回应时

<SCRIPT SRC="http://externalsite.com/ads/sample.js" TYPE="text/javascript"></SCRIPT>

脚本标签没有显示。 我需要在我的 .js 文件中加载 .php 文件

最佳答案

试试这个..

echo "<SCRIPT SRC='http://externalsite.com/ads/sample.js' TYPE='text/javascript'></SCRIPT>";

关于javascript - 无法在php中调用脚本标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34736351/

相关文章:

javascript - 加载其文件夹之外的页面(ajax)

javascript - 如何使用javascript替换字符串中所有匹配的纯文本字符串(但不是标签或属性)?

javascript - 如何从 html 文本框中获取输入并将其分配给 javascript 变量?

javascript - jqueryUI - 将项目拖到多个列表

php - 如何在一个可以具有不同值的属性上查找

javascript - jQuery 驼峰式映射从 "data-"属性名称到 ".data()"键

javascript - 时间选择器操作未触发

php - PHP 中的 mssql_connect 不存在

javascript - Jquery Animate 高度切换

javascript - 如何将 HTTP 方法传递给 window.open