我在下面有这个脚本,它运行良好。当我直接加载 .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/