读书人

jquery出现谷歌与IE和火狐的差异怎么解

发布时间: 2012-12-31 11:57:51 作者: rapoo

jquery出现谷歌与IE和火狐的差异如何解决


$("#provinceOne").change(function(e){
$("#cityOne option").attr("hidden",true).html('');
e.preventDefault();
/*POST title to server*/
var provinceOne = $("#provinceOne").val();
$.ajax({
url: '<%=request.getContextPath()%>/mgr/places/findCitys',
type: 'POST',
contentType: "application/json;charset=UTF-8",
data: JSON.stringify({name:provinceOne}),
dataType: 'text',
success: function(data){
eval("cityOneArray="+data)
for(var i = 0 ; i<cityOneArray.length;i++){
$("#cityOne").append("<option>"+cityOneArray[i]+"</option>");
}
},error:function(){}
});
/* window.location.href=window.location.href; */
});
});



实现功能是 所在省份 ****
所在城市 ****

出现的问题是在谷歌浏览器下点击省份下拉框前三次可以正常显示所在城市下拉框
到了第四次所在城市为空的,但是在IE,火狐能正常显示
不知道是不是这段出现的问题:$("#cityOne option").attr("hidden",true).html('');
我写了好几种写法都是不行的:$("#cityOne option").hide().html('');
谷歌浏览器版本为:版本 22.0.1229.94 m


[解决办法]
你的代码在IE下能运行?IE8-没有JSON对象,IE9+不清楚,没有IE9+

 $("#provinceOne").change(function(e){
$("#cityOne option").attr("hidden",true).html('');
e.preventDefault();
/*POST title to server*/
var provinceOne = $("#provinceOne").val();
$.ajax({
url: '<%=request.getContextPath()%>/mgr/places/findCitys',
type: 'POST',
contentType: "application/json;charset=UTF-8",
//data: JSON.stringify({name:provinceOne}),
data: {name:provinceOne},//////该这样就行了,jq会自动转换的
dataType: 'text',
success: function(data){
eval("cityOneArray="+data)
for(var i = 0 ; i<cityOneArray.length;i++){
$("#cityOne").append("<option>"+cityOneArray[i]+"</option>");


}
},error:function(xhr){alert('错误了\n\n'+xhr.responseText)}//加错误回调看看是不是出错了
});
/* window.location.href=window.location.href; */
});
});

读书人网 >Ajax

热点推荐