doutuanxiao4619 2014-05-16 06:20
浏览 38

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

I implemented a search form that has 3 drop down <select> tags The first 2 drop downs have static options while I used a javascript to create the options of the third drop down. The javascript is based on onchange event of 2nd drop down and is stored in searchideas.js file

This searchideas.js file calls datasupplier.php using GET method through XMLHttpRequest. All works fine on my localhost but when I hosted it on the live website, the options for the third drop down does not gets generated. xmlhttp.readyState becomes 4 but xmlhttp.status becomes 500 which corresponds to Internal server error.

I have also moved the searchideas.js and datasupplier.php in the same folder where my webpage containing the dropdowns is located but to no avail.

How can I over come this error?

My searchideas.js is:

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

My datasupplier.php is:

<?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条回答 默认 最新

  • douzong5057 2015-01-09 08:04
    关注

    I had the same problem as you because of file permission , changing permission from 755 to 644 worked. If yours is related to permissions, try setting datasupplier.php's permission to 644.

    评论

报告相同问题?

悬赏问题

  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害