我正在尝试利用 Google 的 API 作为获取用户位置的一种方式。完成此操作后,我将其传递给外部 PHP 脚本,该脚本将进一步输出一些 JavaScript 代码。但是,我无法调用 PHP 脚本:
<script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAKw7Q"></script
<script type="text/javascript">
if(google.loader.ClientLocation)
{
visitor_countrycode = google.loader.ClientLocation.address.country_code;
}
</script>
<script type='text/javascript' src='http://www.mysite.com/widget.php?mid=12&c=visitor_countrycode'>
</script>
以上是从我的数据库中检索到的内容。然而,该变量visitor_countrycode
不会在 HTML 中生成,它仍然包含字符串“ visitor_countrycode
”而不是其 Javascript 值。
我就是想不通。
更新
我实际上可以使用 JQuery:
我已经尝试过了,但我没有得到太多的运气。
$("<script type='text/javascript' scr='http://www.mysite.com/widget.php?mid=12&c="+visitor_countrycode+"'").appendTo('body');
有什么问题吗?