Php和javascript工作在本地主机,但不是在托管网站

Php and javascript working on localhost but not on hosted website

本文关键字:网站 主机 javascript 工作 Php      更新时间:2023-09-26

我实现了一个搜索表单,它有3个下拉<select>标签前2个下拉菜单有静态选项,而我使用javascript创建第三个下拉菜单的选项。javascript是基于onchange的第二个下拉事件,并存储在searchideas.js文件

这个searchideas.js文件通过XMLHttpRequest使用GET方法调用datasupplier.php。在我的本地主机上所有的工作都很好,但是当我在现场网站上托管它时,第三个下拉菜单的选项不会生成。xmlhttp.readyState变为4, xmlhttp.status变为500,对应服务器内部错误。

我还将searchideas.jsdatasupplier.php移动到包含下拉菜单的网页所在的文件夹中,但无济于事。

我怎样才能克服这个错误?

我的searchideas.js是:

function searchideas( )
{
    var state = document.getElementById("stateID").value; 
    var county = document.getElementById("countyID").value; 
    var town = document.getElementById("townID").value;
    var xmlhttp;
    if (window.XMLHttpRequest)
    {
        xmlhttp=new XMLHttpRequest();
    }
    else
    {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {        
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            var selectList = document.getElementById('townID');
            var val = xmlhttp.responseText; 
            var jsonData = JSON.parse(val); 
            for (var i in jsonData) 
            {
              var option = document.createElement('option');
              option.value = "http://www.mywebsite.com" + i;
              option.text = jsonData[i];
              selectList.appendChild(option);
            }
        }   
    } 
    var url = "http://www.mywebsite.com/sites/all/themes/danland/datasupplier.php?stateID=" + state + "&countyID=" + county + "&townID=" + town;    
    xmlhttp.open("GET",url,true);
    xmlhttp.send();
}

我的datasupplier.php是:

<?php 
$stateID = $_GET['stateID'];
$countyID = $_GET['countyID'];
$townID = $_GET['townID'];
$states = array();
$states['SC'] = "Stories";
$states['TL'] = "Novels";
$counties = array();
$counties['SC']['PRACT'] = 'By Interest';
$counties['SC']['SERV'] = 'By Choice';
$counties['TL']['PRACT'] = 'By Interest';
$counties['TL']['SERV'] = 'By Choice';
$towns = array();
$towns['SC']['PRACT']['/index.php?q=sc%3Fpract%3Ffai'] = "Fairy Tale";
$towns['SC']['PRACT']['/index.php?q=sc%3Fpract%3Fedu'] = "Education";
$towns['SC']['SERV']['/index.php?q=sc%3Fserv%3Ffic'] = "Fiction";
$towns['TL']['PRACT']['/index.php?q=tl%3Fpract%3Fzom'] = "Zombie";
$towns['TL']['PRACT']['/index.php?q=tl%3Fpract%3Fedu'] = "Education";
$towns['TL']['SERV']['/index.php?q=tl%3Fserv%3Fsal'] = "Sales";
$towns['TL']['SERV']['/index.php?q=tl%3Fserv%3Fstr'] = "Strategy";

if($stateID && !$countyID && !$townID)
{
    echo json_encode( $counties[$stateID] );
} 
elseif( $stateID && $countyID && !$townID ) 
{
    echo json_encode( $towns[$stateID][$countyID] );
}
elseif( isset($villages[$stateID][$countyID][$townID]) ) 
{
    echo json_encode( $villages[$stateID][$countyID][$townID] );
} 
else 
{
    echo '{}';
}
?>

由于文件权限,我遇到了与您相同的问题,将权限从755更改为644工作。如果您的权限与权限有关,请尝试将datasupplier.php的权限设置为644