我有一个php文件,它返回一个JSON编码的结果。我正在使用:
$.GET("thephpfile.php",function(data){
ipaddress = data['ip_address'];
document.write(ipaddress)
});
" thephpfile.php"与javascript页面位于同一文件夹中。目前,我得到一个空白页面。但是当我添加完整路径时,它的工作原理如下:
$.GET("http://locahost/thephpfile.php",function(data){
ipaddress = data['ip_address'];
document.write(ipaddress)
});
如何解决此问题?
答案 0 :(得分:1)
请使用以下代码解决方案。
<?php
define("ROOT_WWW","http://".$_SERVER['HTTP_HOST'] ."/yourprojectname/");
?>
<script type="text/javascript">
var ajax_folder="<?= ROOT_WWW ?>";
</script>
$.GET(ajax_folder+"thephpfile.php",function(data){
ipaddress = data['ip_address'];
document.write(ipaddress)
});
答案 1 :(得分:0)
$.GET("/thephpfile.php",function(data){
ipaddress = data['ip_address'];
document.write(ipaddress)
});