Javascript 服务器端URL返回空响应
我有一个php文件,它返回一个JSON编码的结果。即时通讯使用:Javascript 服务器端URL返回空响应,javascript,php,jquery,Javascript,Php,Jquery,我有一个php文件,它返回一个JSON编码的结果。即时通讯使用: $.GET("thephpfile.php",function(data){ ipaddress = data['ip_address']; document.write(ipaddress) }); “theppfile.php”与javascript页面位于同一文件夹中。目前,我得到一个空白页。但当我添加完整路径时,它的工作原理如下: $.GET("http://locahost/thephpfile.
$.GET("thephpfile.php",function(data){
ipaddress = data['ip_address'];
document.write(ipaddress)
});
“theppfile.php”与javascript页面位于同一文件夹中。目前,我得到一个空白页。但当我添加完整路径时,它的工作原理如下:
$.GET("http://locahost/thephpfile.php",function(data){
ipaddress = data['ip_address'];
document.write(ipaddress)
});
如何解决此问题?请使用以下代码解决此问题
$.GET("/thephpfile.php",function(data){
ipaddress = data['ip_address'];
document.write(ipaddress)
});
<?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)
});
var ajax_folder=“”;
$.GET(ajax\u文件夹+“theppfile.php”,函数(数据){
ip地址=数据['ip_地址'];
document.write(ipaddress)
});
在文件位置后添加一个结束符。获取(“http://blah/phpfile.php,函数…修复了它,但这并不是错误的原因…添加一个前导斜杠:$.GET(“/theppfile.php”
这将使路径成为绝对路径。