Heim  >  Artikel  >  Backend-Entwicklung  >  Ajax在火狐浏览器中的兼容有关问题,程序在IE中运行正常

Ajax在火狐浏览器中的兼容有关问题,程序在IE中运行正常

WBOY
WBOYOriginal
2016-06-13 13:11:30769Durchsuche

Ajax在火狐浏览器中的兼容问题,程序在IE中运行正常
var xmlHttp=false;
function createXMLHttp(){
try{
xmlHttp=new XMLHttpRequest();
}catch(trymicrosoft){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}catch(othermicrosoft){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}catch(failed){
xmlHttp=false;
}
}
}
if(!xmlHttp){
alert("无法创建 XMLHttpRequest 对象!");
}
}
function Ajaxcheck(){
var num=document.myform.uname.value;//获得表单的数据
var url="check.php?n="+num;
createXMLHttp();
xmlHttp.open("GET",url,true);//这里的true代表是异步请求
xmlHttp.onreadystatechange=updatePage;
xmlHttp.send(null);
}
 
function updatePage(){
if(xmlHttp.readyState==4){
var response=xmlHttp.responseText;
if(response=="ok"){
document.myform.nameerr.value="√";
return true;
}else if(response=="no"){
document.myform.nameerr.value="×用户名已占用";
return false;
}else{
document.myform.nameerr.value="服务器出现问题";
return false;
}
}





代码如上,我是用Ajax检测用户名是否存在,在火狐中,要是英文母的名字,可以正常,要是中文名字就判断不出来了,怎么回事啊?????

------解决方案--------------------
应该是在Ajaxcheck 发送请求的时候出错,可能是中文导致的问题,
你可以在check.php页面里面echo 用户名,看取到的是否是乱码, 如果是乱码的话用urlencode处理一下
------解决方案--------------------
var url="check.php?n="+num; 
url=encodeURI(url);
------解决方案--------------------
在check.php页面里面echo 用户名,看取到的是否是乱码, 如果是乱码的话用urlencode处理一下
------解决方案--------------------

探讨
引用:数据库编码是什么?注册页面脚本编码是什么?两个是一致吗?,不一致的话得用iconv()函数将数据字符编码转换一下
我数据库里,数据库,表,字段都是用的gb2312,在check.php中也加入了mysql_query("set character set gb2312");
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel: PHP定时施行 Nächster Artikel: php讯息队列