我的jquery ajax似乎不适用于ie6

时间:2010-06-04 12:14:16

标签: php jquery ajax

我在我的项目中使用jquery ajax在我的Firefox中运行良好但它似乎在IE6中不起作用 如何使jquery Ajax在Ie6中工作 这是我的代码

function Load_State(inp)
{

$.ajax({
   type: "GET",
   url: "<?=base_url()?>/system/application/views/ssitAjax.php",
   data: "selCurCountry="+inp,
   success: function(msg){
     //alert(  msg );
     document.getElementById('selCurState').innerHTML=msg;
   }
 });
} 
function Load_City(inp)
{

$.ajax({
   type: "GET",
   url: "<?=base_url()?>/system/application/views/ssitAjax.php",
   data: "selCurState="+inp,
   success: function(msgq){
    //alert(  msgq );
     document.getElementById('selCurCity').innerHTML=msgq;
   }
 });
}

这是我的ssit ajax页面

<?php

include('dbConnection.php');

session_start();
if(($_GET['selCurCountry']!="") || (isset($_GET['selCurCountry'])))
{

             $Country = $_GET['selCurCountry'];
             $_SESSION['Country'] = $Country;

            $query = "SELECT dState_id,dStateName 
                            FROM tbl_state
                            WHERE dCountry_id='$Country'
                            AND dIsDelete='0'";


            $result = mysql_query($query,$cn) or die("Selection Query Failed !!!");

            echo '<option value="0">Select The State</option>';

            while($rowset = mysql_fetch_array($result))
             {
               echo "<option value='".$rowset[0]."'>".$rowset[1]."</option>";
             }

}
else if(($_GET['selCurState']!="") || (isset($_GET['selCurState'])))
{

            $State = $_GET['selCurState'];
            $_SESSION['state'] = $State;
            $query = "SELECT dCity_id,dCityName FROM tbl_city
                        WHERE dState_id='$State'
                        AND dIsDelete='0'";


            $result = mysql_query($query,$cn) or die("Selection Query Failed !!!");


            echo '<option value="0">Select The City</option>';

            while($rowset = mysql_fetch_array($result))
             {
               echo "<option value='".$rowset[0]."'>".$rowset[1]."</option>";
             }



}?>

编辑:

 <option value="0">Select The State</option>
 <option value='1'>Andhra Pradesh</option><option value='2'>Arunachal Pradesh</option><option value='3'>Assam</option><option value='4'>Bihar</option><option value='5'>Chandigarh</option><option value='6'>Chhattisgarh</option><option value='7'>Dadra and Nagar Haveli</option><option value='8'>Daman and Diu</option><option value='9'>Delhi</option><option value='10'>Goa</option><option value='11'>Gujarat</option><option value='12'>Haryana</option><option value='13'>Himachal Pradesh</option><option value='14'>Jammu and Kashmir</option><option value='15'>Jharkhand</option><option value='16'>Karnataka</option><option value='17'>Kerala</option><option value='18'>Lakshadweep</option><option value='19'>Madhya Pradesh</option><option value='20'>Maharashtra</option><option value='21'>Manipur</option><option value='22'>Meghalaya</option><option value='23'>Mizoram</option><option value='24'>Nagaland</option><option value='25'>Orissa</option><option value='26'>Puducherry</option><option value='27'>Punjab</option><option value='28'>Rajasthan</option><option value='29'>Sikkim</option><option value='30'>Tamil Nadu</option><option value='31'>Tripura</option><option value='32'>Uttar Pradesh</option><option value='33'>Uttarakhand</option><option value='34'>West Bengal</option>

2 个答案:

答案 0 :(得分:1)

哦等一下 - 我想我知道问题是什么。在IE6中,您不能仅仅替换<select>元素的“innerHTML”。您必须从头开始重建整个<select>。 (或者您可以清空options元素上的<select>数组,并使用DOM API重建它们。)

尝试在<select>标记中包含<span>元素(带有“id”值),然后重建其中的“innerHTML”,再次添加<select>元素。这是我所知道的痛苦,它可能会弄乱其他东西,但这是一个很好的实验来证实我的怀疑。

答案 1 :(得分:0)

我以前没有经历过PHP,但在IE中使用ajax / get / post调用时有类似的怪异。您是否尝试过指定内容类型?

$.ajax({ url: "/home/myPage.aspx",
         type: "GET",
         data: { selCurrCountry: inp }, 
         content-type: "application/json",
         success: function(data) {
            alert("Yay!");
         }
});

此外,如果您在查询字符串中需要该数据值,为什么不将其附加到网址并设置数据:{}或者根本不存在?

$.ajax({ url: "/home/myPage.aspx?selCurCountry=" + inp,
         type: "GET",
         success: function(data) {
            alert("Yay!");
         }
});

希望这有帮助。