Php和javascript工作在localhost但不在托管网站上

时间:2014-05-16 06:20:15

标签: javascript php json drupal

我实施了一个包含3个下拉<select>标记的搜索表单 前两个下拉列表有静态选项,而我使用javascript创建第三个下拉列表的选项。 javascript基于onchange第二次下拉事件,存储在searchideas.js文件中

searchideas.js个文件通过datasupplier.php使用GET方法调用XMLHttpRequest。一切正常在我的本地主机上运行,​​但是当我在实时网站上托管它时,第三个下拉菜单的选项不会生成。 xmlhttp.readyState变为4xmlhttp.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 '{}';
}

?>

1 个答案:

答案 0 :(得分:1)

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