Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.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
Javascript Ajax在IE8中不支持下拉菜单,但它';在其他浏览器中工作正常_Javascript_Php_Ajax_Google Chrome_Internet Explorer 8 - Fatal编程技术网

Javascript Ajax在IE8中不支持下拉菜单,但它';在其他浏览器中工作正常

Javascript Ajax在IE8中不支持下拉菜单,但它';在其他浏览器中工作正常,javascript,php,ajax,google-chrome,internet-explorer-8,Javascript,Php,Ajax,Google Chrome,Internet Explorer 8,我的ajax代码在其他浏览器中运行良好,但在IE中运行不佳 它正在创建XMLHTTPRequest,但我的PHP脚本中的值只是一个空列表 以下是我的Javascript: <script type="text/javascript"> function getcity() { $('#stateerr').hide(); state=document.getElementById("ddlstate").value; //

我的ajax代码在其他浏览器中运行良好,但在IE中运行不佳

它正在创建XMLHTTPRequest,但我的PHP脚本中的值只是一个空列表

以下是我的Javascript:

<script type="text/javascript">
    function getcity()
    {
        $('#stateerr').hide();
        state=document.getElementById("ddlstate").value;
       // alert(state);
        var xmlhttp;
        if (window.XMLHttpRequest)
          {
              alert('in this');
          xmlhttp=new XMLHttpRequest();
          alert(xmlhttp);
          }
        else
          {
            alert('in that');
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
        xmlhttp.onreadystatechange=function()
          {
          if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
            document.getElementById("ddlcity").innerHTML=xmlhttp.responseText;
           alert(xmlhttp.responseText);
            }
          }
          var str="getcity.php?q="+state;
         // alert(str);
        xmlhttp.open("GET",str,true);
        xmlhttp.send();
    }



    function getlocation()
    {
        $('#cityerr').hide();
        city=document.getElementById("ddlcity").value;
        //alert(state);
        var xmlhttp;
        if (window.XMLHttpRequest)
          {
          xmlhttp=new XMLHttpRequest();
          }
        else
          {
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
        xmlhttp.onreadystatechange=function()
          {
          if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
            document.getElementById("ddllocality").innerHTML=xmlhttp.responseText;
           // alert('inhttpresponse');
            }
          }
          var str="getlocation.php?q="+city;
         // alert(str);
        xmlhttp.open("GET",str,true);
        xmlhttp.send();
    }
</script>

函数getcity()
{
$('#stateerr').hide();
state=document.getElementById(“ddlstate”).value;
//警报(状态);
var-xmlhttp;
if(window.XMLHttpRequest)
{
警报(“在本文件中”);
xmlhttp=新的XMLHttpRequest();
警报(xmlhttp);
}
其他的
{
警惕(‘在那’);
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
document.getElementById(“ddlcity”).innerHTML=xmlhttp.responseText;
警报(xmlhttp.responseText);
}
}
var str=“getcity.php?q=“+状态;
//警报(str);
open(“GET”,str,true);
xmlhttp.send();
}
函数getlocation()
{
$('#cityer').hide();
city=document.getElementById(“ddlcity”).value;
//警报(状态);
var-xmlhttp;
if(window.XMLHttpRequest)
{
xmlhttp=新的XMLHttpRequest();
}
其他的
{
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
document.getElementById(“ddlLocation”).innerHTML=xmlhttp.responseText;
//警报('inhttpresponse');
}
}
var str=“getlocation.php?q=“+城市;
//警报(str);
open(“GET”,str,true);
xmlhttp.send();
}
这是我的HTML表单:

<form name="search" action="search.php" method="GET" onsubmit="return searchCheck()">
<table width=100% >
                <tr>
                    <td colspan=3>
                    <div class="backgroundgif" id="backgroundgif" style="height:30px;width:100%">
                    <span style="font-size:15px; color:#CCFFFF;">
                    Search Property
                    </span>
                    </div>
                    </td>
                </tr>
                <tr>
                    <td>Property For
                    </td>
                    <td>
                        Rent <input type="checkbox" name="rentchkbox" id="rentchkbox" value="1" onclick="getRentPriceRange()"/>  
                        Sell<input type="checkbox" name="sellchkbox" id="sellchkbox" value="1"  onclick="getSellPriceRange()"/>      
                    </td>


                </tr>
                <tr>
                    <td>
                        Purpose
                    </td>
                    <td>
                        <select name="purpose">
                        <option>Family</option>
                        <option>Student</option>
                        <option>s</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>Price range
                    </td>
                    <td>
                        <select name="ddlamount1" id="ddlamount1" onchange="hideerr()">
                            <option>select checkbox</option> 
                        </select>
                    </td>
                     <td><div id="ddlamount1err" style="display:none"><img src="IMAGES/errorsmall.png"/></div></td>
                </tr>
                <tr>
                    <td>
                        State
                    </td>
                    <td>
                        <select name="ddlstate" id="ddlstate" onchange="getcity()">
                            <option>select state</option>
                            <option>MAHARASTRA</option>
                        </select>
                    </td>
                    <td><div id="stateerr" style="display:none"><img src="IMAGES/errorsmall.png"/></div></td>
                </tr>
                <tr>
                    <td>
                        City
                    </td>
                    <td>
                        <select name="ddlcity" id="ddlcity" onchange="getlocation()">
                            <option>select city</option>
                            <option>PUNE</option>
                        </select>
                    </td>
                    <td><div id="cityerr" style="display:none"><img src="IMAGES/errorsmall.png"/></div></td>

                </tr>
                <tr>
                    <td>
                        Locality
                    </td>
                    <td>
                        <select name="ddllocality" id="ddllocality">
                            <option>Select Locality</option>
                            <option>indra nagar</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" align="center">
                       <input type="submit" value="Search">
                    </td>
                </tr>
                </table>
                </form>

搜索属性
财产
租
卖
目的
家庭
学生
s
价格范围
选中复选框
陈述
选择状态
马哈拉施特拉
城市
选择城市
浦那
地点
选择地点
因陀罗纳加尔
这是我的PHP脚本。该代码从“州”下拉列表中获取城市

<?php
require_once('connection_class2.php');
$connection=new Dbconnection;
$query="select country_id from country where country_name='$_GET[q]'";
$result=$connection->select($query);
while($row=mysqli_fetch_object($result))
{
 $country_id=$row->country_id;
}

$query1="select state_name from state where country_id='$country_id'";
$result1=$connection->select($query1);

echo '<option>';
echo 'select state';
echo '</option>';
while($rw=mysqli_fetch_object($result1))
{
 $state_name=$rw->state_name;
echo '<option>';
echo $state_name;
echo '</option>';
}
?>


表单中还有其他函数需要验证,但我省略了它们,因为它们似乎不相关。

对于IE中的select元素,innerHTML选项不起作用

因此,最好使用php文件中的选项创建整个select元素并返回它们

然后使用div放置选择框,并使用普通innerHTML属性添加内容

否则

您必须使用javascript添加选项,这与IE和其他浏览器不同。。 以下示例将元素动态添加到选择框中

function displayResult()
{
var x=document.getElementById("mySelect");
var option=document.createElement("option");
option.text="Kiwi";
try
  {
  // for IE earlier than version 8
  x.add(option,x.options[null]);
  }
catch (e)
  {
  x.add(option,null);
  }
}

我认为您可以使用第一个选项,这将很容易。

尝试在两个名为“xmlhttp”的javascript函数中添加不同的变量名。另外,请告诉我是否启动了ajax调用,以及还会发生什么?这段代码在FF n Chrome中运行得很好,但是,它只是在IE中产生了问题。我尝试过更改变量的名称,但仍然不起作用!!n ajax调用将启动,如果您将在该响应条件下发出警报,您将得到它返回响应值,但不会显示在下拉列表中!嘿kvijayhari,我想我遇到了问题n那就是,我正在提醒响应条件中的xmlhttp.responseText,猜怎么着!在FF n chrome中,它在警报框中显示城市值,但在IE中,它只显示第一个选项,即选择城市,但在FF中,它显示所有值,如选择城市1城市2 n等等!!但问题是我得到的回应只有IE!!如果我正在制作一个div n创建整个select元素,它在FF n Chrome中仍然可以正常工作,但在IE中不再工作!!它只显示“选择城市”像一个标签,而不是下拉列表!!在PHP文件中,而不是仅创建,创建如下“select citycity1”,然后在html页面中创建一个div,然后在ajax函数中使用getElementByid获取该div,并使用innerhtml设置。。明白了吗?它应该有用。。