Php和javascript在本地主机上工作,但不在托管网站上工作
我实现了一个具有3个下拉标签的搜索表单 前两个下拉列表具有静态选项,而我使用javascript创建了第三个下拉列表的选项。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
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