Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php和javascript在本地主机上工作,但不在托管网站上工作_Javascript_Php_Json_Drupal - Fatal编程技术网

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

Php和javascript在本地主机上工作,但不在托管网站上工作,javascript,php,json,drupal,Javascript,Php,Json,Drupal,我实现了一个具有3个下拉标签的搜索表单 前两个下拉列表具有静态选项,而我使用javascript创建了第三个下拉列表的选项。javascript基于第二个下拉列表中的onchange事件,存储在searchideas.js文件中 这个searchideas.js文件通过XMLHttpRequest使用GET方法调用datasupplier.php。所有这些都可以在我的本地主机上正常工作,但当我在live网站上托管它时,第三个下拉列表的选项不会生成xmlhttp.readyState变为4,但xm

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

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

我还将
searchideas.js
datasupplier.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();
}
<?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 '{}';
}

?>
我的
datasupplier.php
是:

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();
}
<?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