从javascript调用php文件出错[HTTP/1.1 301永久移动807ms]


error on call to php file from javascript [HTTP/1.1 301 Moved Permanently 807ms]

我有一个javascript代码,它调用php文件并接收输出。我的javascript代码是

 function properties(location) {
    if(window.XMLHttpRequest)
        xmlHttpRequest=new XMLHttpRequest();
    else if(window.ActiveXObject)
        xmlHttpRequest=new ActiveXObject("Microsoft.XMLHTTP");
    xmlHttpRequest.open('GET','myfile.php?region='+region,true);
    xmlHttpRequest.onreadystatechange=function() {
        if(xmlHttpRequest.readyState==4)    
          alert(xmlHttpRequest.responseText);
    }
    xmlHttpRequest.send();
  } 

代码在本地主机上运行良好,我收到了输出,但是当我在实时服务器上尝试它时,它不起作用,并且在浏览器的控制台中显示以下消息

[14:36:20.350] GET http://mysite.com/myfile.php?region=South [HTTP/1.1 301 Moved Permanently 807ms]

,它也给了我另一个网址,任何形式的帮助是非常感激。

打开你的浏览器,这样做。

尝试URL带"www.",并检查它是否重定向到非www。也可以尝试不带www.并检查重定向。

看到最终位置后,在代码中编辑url位置。

你也可以检查服务器上的。htaccess文件,看看它是否有重定向。

xmlHttpRequest.open('GET','myfile.php?region='+region,true);

此处给出完整的路径或正确的相对url。

尝试在发送到服务器之前添加您的基本url

var baseurl = 'yoursite.com';
xmlHttpRequest.open('GET',baseurl+'myfile.php?region='+region,true);