我实现了一个有 3 个下拉列表的搜索表单 <select>
标签
前两个下拉菜单有静态选项,而我使用 JavaScript 创建第三个下拉菜单的选项。 javascript基于onchange
第二次下拉事件存储在searchideas.js
中文件
这个searchideas.js
文件调用datasupplier.php
使用GET
方法通过XMLHttpRequest
。在我的本地主机上一切正常,但是当我将其托管在实时网站上时,不会生成第三个下拉列表的选项。 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();
}
我的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
。
关于javascript - Php 和 javascript 在本地主机上工作,但在托管网站上不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23693792/