php和javascript在本地主机上工作,但不在托管网站上 [英] Php and javascript working on localhost but not on hosted website

查看:140
本文介绍了php和javascript在本地主机上工作,但不在托管网站上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现了一个搜索表单,其中有3个下拉菜单< select> 标签
当我使用javascript创建时,前2个下拉菜单中有静态选项第三个下拉菜单的选项。 javascript基于第二次下载的 onchange 事件,并存储在 searchideas.js 文件

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

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

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.

我还移动了 searchideas.js datasupplier.php 在我的网页包含下拉列表位于同一个文件夹,但无效。

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?

我的 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

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 '{}';
}

?>


推荐答案

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

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.

这篇关于php和javascript在本地主机上工作,但不在托管网站上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆