ajax实现三级联动 为什么输出的是乱码,我都把xmlHttp改成xmlHttpRequest 10
输出结果是创建的select.php<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www...
输出结果
是
创建的select.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <script> function createAjax(){ var xmlHttpRequest = false; if (window.XMLHttpRequest){ xmlHttpRequest = new XMLHttpRequest(); }else if(window.ActiveXObject){ try{ xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP"); }catch(e){ try{ xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){ xmlHttpRequest= false; } } } return xmlHttpRequest; } var ajax = null; function getCity(province_id){ ajax = createAjax(); ajax.onreadystatechange=function(){ if(ajax.readyState == 4){ if(ajax.status == 200){ var cities = ajax.responseXML.getElementsByTagName("city"); $('city').length = 0; var myoption = document.createElement("option"); myoption.value = ""; myoption.innerText = "--请选择城市--"; $('city').appendChild(myoption); for(var i=0;i<cities.length;i++){ var city_id = cities[i].childNodes[0].childNodes[0].nodeValue; var city_name = cities[i].childNodes[1].childNodes[0].nodeValue; var myoption = document.createElement("option"); myoption.value = city_id; myoption.innerText = city_name; $('city').appendChild(myoption); } } } } ajax.open("post","selectPro.php",true); ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); ajax.send("province_id="+province_id); } function getCounty(city_id){ ajax = createAjax(); ajax.onreadystatechange=function(){ if(ajax.readyState == 4){ if(ajax.status == 200){ var cities = ajax.responseXML.getElementsByTagName("county"); $('county').length = 0; var myoption = document.createElement("option"); myoption.value = ""; myoption.innerText = "--请选择县--"; $('county').appendChild(myoption); for(var i=0;i<cities.length;i++){ var city_id = cities[i].childNodes[0].childNodes[0].nodeValue; var city_name = cities[i].childNodes[1].childNodes[0].nodeValue; var myoption = document.createElement("option"); myoption.value = city_id; myoption.innerText = city_name; $('county').appendChild(myoption); } } } } ajax.open("post","selectPro.php",true); ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); ajax.send("city_id="+city_id); } function $(id){ return document.getElementById(id); } </script> </head> <body> </body> </html>
是来源于 http://www.phpddt.com/php/769.html
是在火狐浏览器运行
编码是 mysql_query('set names utf8');
firefox下无法用childNodes[0].nodeValue正常读取节点的值解决办法 展开
是
创建的select.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <script> function createAjax(){ var xmlHttpRequest = false; if (window.XMLHttpRequest){ xmlHttpRequest = new XMLHttpRequest(); }else if(window.ActiveXObject){ try{ xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP"); }catch(e){ try{ xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){ xmlHttpRequest= false; } } } return xmlHttpRequest; } var ajax = null; function getCity(province_id){ ajax = createAjax(); ajax.onreadystatechange=function(){ if(ajax.readyState == 4){ if(ajax.status == 200){ var cities = ajax.responseXML.getElementsByTagName("city"); $('city').length = 0; var myoption = document.createElement("option"); myoption.value = ""; myoption.innerText = "--请选择城市--"; $('city').appendChild(myoption); for(var i=0;i<cities.length;i++){ var city_id = cities[i].childNodes[0].childNodes[0].nodeValue; var city_name = cities[i].childNodes[1].childNodes[0].nodeValue; var myoption = document.createElement("option"); myoption.value = city_id; myoption.innerText = city_name; $('city').appendChild(myoption); } } } } ajax.open("post","selectPro.php",true); ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); ajax.send("province_id="+province_id); } function getCounty(city_id){ ajax = createAjax(); ajax.onreadystatechange=function(){ if(ajax.readyState == 4){ if(ajax.status == 200){ var cities = ajax.responseXML.getElementsByTagName("county"); $('county').length = 0; var myoption = document.createElement("option"); myoption.value = ""; myoption.innerText = "--请选择县--"; $('county').appendChild(myoption); for(var i=0;i<cities.length;i++){ var city_id = cities[i].childNodes[0].childNodes[0].nodeValue; var city_name = cities[i].childNodes[1].childNodes[0].nodeValue; var myoption = document.createElement("option"); myoption.value = city_id; myoption.innerText = city_name; $('county').appendChild(myoption); } } } } ajax.open("post","selectPro.php",true); ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); ajax.send("city_id="+city_id); } function $(id){ return document.getElementById(id); } </script> </head> <body> </body> </html>
是来源于 http://www.phpddt.com/php/769.html
是在火狐浏览器运行
编码是 mysql_query('set names utf8');
firefox下无法用childNodes[0].nodeValue正常读取节点的值解决办法 展开
2个回答
2014-02-25
展开全部
编码问题吧
追问
编码的问题,那要改成什么呀
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-02-25
展开全部
url传输是已utf-8格式的,获取后需要转码
追问
怎么转换,说清楚点 麻烦写下 谢谢 赐教
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询