[英]Jquery ajax select drop down works in FF and chrome but not IE 7-9
I know this has been asked so many times by now you all are probably sick of it. 我知道这个问题已经被问过很多次了,大家可能已经厌倦了。 I'm just stuck and have already spent about 4 hours on this.
我只是被困住了,已经花了大约4个小时了。 I've read through many suggestions already about the
我已经阅读了许多有关
cache:false,
option and adding certain "content-types", but when I do this, it no longer works in any browser. 选项并添加某些“内容类型”,但是当我这样做时,它在任何浏览器中都不再起作用。
I followed the tutorial as found here: http://www.x-developer.com/php-scripts/loading-drop-downs-with-ajax-php-and-fetching-values-from-database-without-refreshing-the-page 我按照此处找到的教程进行操作: http : //www.x-developer.com/php-scripts/loading-drop-downs-with-ajax-php-and-fetching-values-from-database-without-refreshing-这一页
and I modified it of course to my needs, mostly just the mysql and identifiers. 我当然根据自己的需要修改了它,大部分只是mysql和标识符。
This is what I have in my head section: 这是我的头部内容:
<script type="text/javascript">
function get_cities(country)
{
$.ajax({
type: "POST",
url: "/cities.php",
cache: false,
beforeSend: function () {
$("#state").html("<option>Loading ...</option>");
},
data: "country="+country,
success: function(msg){
$("#state").html(msg);
}
});
}
</script>
In IE, it gets to the Loading.... part, and does nothing, it doesn't populate the option field as it does in Chrome and FF. 在IE中,它进入“正在加载...”部分,并且什么也不做,它不会像在Chrome和FF中那样填充选项字段。
Do you see anything in the tutorial that he may have left out that is crucial for the operation in IE? 您是否在本教程中看到他可能遗漏的任何内容,这些内容对于IE中的操作至关重要?
Thanks, 谢谢,
Try setting the data object as a key value pair.. 尝试将数据对象设置为键值对。
Instead of 代替
data: "country="+country,
try 尝试
data: { "country" : country },
assuming your $("#state")
is already a dropdown list. 假设您的
$("#state")
已经是一个下拉列表。
in cities.php
, you'll need to remove the <select>
tag. 在
cities.php
,您需要删除<select>
标记。
<?php
// Code for cities.php
$country_id = $_REQUEST['country_id'];
$sql_city = "SELECT * FROM CITY WHERE country_id = '".$country_id."'";
$result_city = mysql_query($sql_city);
// REMOVE THIS LINE
//echo "<select name='city'>";
while($row_city = mysql_fetch_array($result_city))
{
echo "<option value='".$row_city['id']."'>".$row_city['city']."</option>";
}
// AND REMOVE THIS LINE
// echo "</select>";
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.