ajax php mysql乱码_php + mysql + ajax乱码问题。。。。

--------------------------最开始------------------------<?php //连接数据库$conn=mysql_connect("localhost","root","123456");if(!$conn){die("数据库连接失败...".mysql_error()...

--------------------------最开始------------------------

//连接数据库

$conn = mysql_connect("localhost","root","123456");

if(!$conn){

die ("数据库连接失败...".mysql_error());

}

mysql_select_db("testajax",$conn);

mysql_query("set names 'gb2312'");

//查询语句

$sql = "select * from country_info";

$result = mysql_query($sql);

echo "国家:";

echo "请选择国家";

while($row = mysql_fetch_array($result)){

echo "---".$row['countryName']."---";

}

echo "  ";

echo "";

mysql_close($conn);

?>

---------------------------script----------------------------------

function getCountry(countryId){

//创建 XMLHTTP 对象

xmlHttp = GetXmlHttpObject();

if(xmlHttp == null){

alert("浏览器请求失败...");

return;

}

var url = "doCountry.php?countryId="+countryId;

//alert(url);

/* */

//xmlHttp.setRequestHeader('charset','utf-8');

xmlHttp.onreadystatechange=function(){

if(xmlHttp.readyState==4 && xmlHttp.status==200){

document.getElementById("capital").innerHTML=xmlHttp.responseText;

}

}

xmlHttp.open("GET",url,true);

xmlHttp.send(null);

}

//得到 xmlhttp 对象

function GetXmlHttpObject(){

var xmlHttp = null;

try{

//web 标准

xmlHttp = new XMLHttpRequest();

}catch (e){

try{

//微软的方式

xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");

}catch (e){

//Internet Explorer 5.5

xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");

}

}

return xmlHttp;

}

-----------------------------php--------------------------

$countryId = $_GET["countryId"];

//连接数据库

$conn = mysql_connect("localhost","root","123456");

if(!$conn){

die ("连接数据库失败...".mysql_error());

}

mysql_select_db("testajax",$conn);

mysql_query("set names 'gb2312'");

//查询语句

$sql = "select * from capital_info where countryId = '".$countryId."'";

$result = mysql_query($sql);

echo "城市:";

echo "请选择城市";

while($row = mysql_fetch_array($result)){

echo "---".$row['capitalName']."---";

}

echo "";

mysql_close($conn);

?>

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值