AJAX使用post发送数据xml格式接受数据


当前第2页 返回上一页

if(window.ActiveXObject) //IE取回XML文件方法
{
var doc = new ActiveXObject("MSxml2.DOMDocument");

doc.loadXML(xmlObject.responseText);

info = doc.getElementsByTagName(tagName);

}
else //---------------------------非IE取回XML文件方法
{
info = xmlObject.responseXML.getElementsByTagName(tagName);

}

return info;
}

function $(id)//常用函数,通过ID取对象
{
return document.getElementById(id);
}

function getProvice()//获取省
{
thisId = "Province";

var id = '1';

ajaxCall(id);

}

function getCity()//获取市
{
thisId = "City";

$("County").length = 0;

var id = $("Province").value;

ajaxCall(id);

}

 

function getCounty()//获取县城
{
thisId = "County";

var id = $("City").value;

if($("City").length)
{
ajaxCall(id);
}

}

window.onlaod = getProvice();//页面开始载入省

</script>
</head>

<body>
<form action="javascript:void(0)" method="post">
<label for="username" >用户名:</label> <input type="text" name="username" id="username" width="60px" /><br />
<label for="psd" >密 &nbsp;码:</label> <input type="password" name="psd" id="psd" width="80px" /></br>
<label for="psd" >地 &nbsp;址:</label>
<select id="Province" onclick="getCity()">
</select>&nbsp;

<select id="City" onclick="getCounty()" >
</select>&nbsp;

<select id="County" name="xian" >
</select>
<input type="submit" value="提交" />
</form>
</body>
</html>

chuli.php

代码如下:

<?php
//3号线
header("Cache-Control:no-cache");

header("Content-Type: text/xml; charset=gb2312");//这里要写XML

require("function.php");

$id = $_POST['id'];

file_put_contents("my1.txt",$act . "------" . $ziduan);

$result = getresultById($id);

$info = "<mes>";

foreach($result as $row)
{
$info .= "<res>";

$info .= "<id>" . $row['region_id'] . "</id>";

$info .= "<name>" . $row['region_name'] . "</name>";

$info .= "</res>";
}

$info .= "</mes>";

echo $info;


?>

 

3.数据库函数


function.php

代码如下:

<?php

function getresultById($id)
{
$con = mysql_connect("localhost","root","");

if($con)
{
$charset = "gb2312";
mysql_query("SET character_set_connection=$charset, character_set_results=$charset, character_set_client=binary"); //这句是必须的,解决中文乱码加密问题s
mysql_select_db("ajax",$con);

$sql = "select * from ecs_region where parent_id = '$id'";

$res = mysql_query($sql);
$arr = array();
while($row = mysql_fetch_assoc($res))
{
$arr[] = $row;
}

return $arr;
}
return false;
}

更多ECSHOP内容来自木庄网络博客


标签:ECSHOP

返回前面的内容

相关阅读 >>

支付宝小程序实现省市区三级联动

php undefined index报错的修复方法

mpvue构建小程序的方法(步骤+地址)

ECSHOP二次开发之购物车分析

ECSHOP后台拿shell方法总结

ECSHOP 2.72如何修改后台访问地址

2019 php面试题与常用技巧大全

企业建站的基础性常识和资源分析

国内一些常用php的cms的nginx服务器的伪静态规则整理

fsockopen pfsockopen函数被禁用,smtp发送邮件不正常的解决方法

更多相关阅读请进入《ECSHOP》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...