• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

ajax乱码有关问题

php 搞代码 3年前 (2022-01-23) 20次浏览 已收录 0个评论

ajax乱码问题
参考一个ajax分页的代码,由于要连接sql server2000,把原代码的utf8改为gb2312,结果点击上一页下一页出现乱码,数据库已经默认是gb2312_chinese_ci了
代码如下:

php代码:

PHP code

<!---ecms Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><title>PHP+ajax分页演示</title><p>4本文¥来源gao!%daima.com搞$代*!码$网9</p><pre>搞代gaodaima码

<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″/><script language=”javascript” src=”ajaxpage.js”></script>

<?php$terry=mysql_connect(“localhost”,”root”,”mindy”)or die(“连接数据库失败:”.mysql_error());mysql_select_db(“page”,$terry);mysql_query(“set NAMES ‘gb2312′”);$result=mysql_query(“select * from tb_user”);$total=mysql_num_rows($result) or die(mysql_error());$page=isset($_GET[‘page’])?intval($_GET[‘page’]):1;$page_size=4;$url=’index.php’;$pagenum=ceil($total/$page_size);$page=min($pagenum,$page);$prepage=$page-1;$nextpage=($page==$pagenum?0:$page+1);$pageset=($page-1)*$page_size;$pagenav=”;$pagenav.=”显示第“.($total?($pageset+1):0).”-“.min($pageset+5,$total).”记录 共“.$total.”条记录 现在是第 “.$page.” 页 “;if($page$pagenum){ echo “error:没有此页”.$page; exit();}?>

<?php$info=mysql_query(“select * from tb_user order by id desc limit $pageset,$page_size”);while($array=mysql_fetch_array($info)){?>

<?php }?>

用户名 用户密码
<?php echo $array[‘id’];?> <?php echo $array[‘username’];?>

<?phpecho “

$pagenav

“;?>

js代码

JScript code

var http_request=false;  function send_request(url){//初始化,指定处理函数,发送请求的函数    http_request=false;    //开始初始化XMLHttpRequest对象    if(window.XMLHttpRequest){//Mozilla浏览器     http_request=new XMLHttpRequest();     if(http_request.overrideMimeType){//设置MIME类别       http_request.overrideMimeType("text/xml");     }    }    else if(window.ActiveXObject){//IE浏览器     try{      http_request=new ActiveXObject("Msxml2.XMLHttp");     }catch(e){      try{      http_request=new ActiveXobject("Microsoft.XMLHttp");      }catch(e){}     }    }    if(!http_request){//异常,创建对象实例失败     window.alert("创建XMLHttp对象失败!");     return false;    }    http_request.onreadystatechange=processrequest;    //确定发送请求方式,URL,及是否同步执行下段代码    http_request.open("GET",url,true);    http_request.send(null);  }  //处理返回信息的函数  function processrequest(){   if(http_request.readyState==4){//判断对象状态     if(http_request.status==200){//信息已成功返回,开始处理信息      document.getElementById(reobj).innerHTML=http_request.responseText;     }     else{//页面不正常      alert("您所请求的页面不正常!");     }   }  }  function dopage(obj,url){   document.getElementById(obj).innerHTML="正在读取数据...";   reobj = obj;   send_request(url);   } 


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:ajax乱码有关问题
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址