ajax后台如何返回xml值
3个回答
展开全部
给你两个我用过的例子,改成你所需要的即可
1 PHP的
if(!$iiiiiid=$_GET["st1"])$iiiiiid="1";
if(!$selectd=$_GET["st2"])$selectd="1";
$dbc = new AccessAdoCon();
$con = $dbc->connect;
$rst = @new COM("ADODB.RecordSet");
$sql ="select * from 产品二级分类 where upid=$iiiiiid";
$rst->Open($sql,$con,1,3);
header("Content-Type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"gb2312\"?>\n";
echo "<sort>\n";
while(!$rst->EOF){
$iiiiiid=$rst->Fields["uid"]->Value;
$sotname=$rst->Fields["name"]->Value;
if($selectd==$iiiiiid)$isseed="YES"; else $isseed="NO";
echo "<count>\n";
echo "<sid>".$iiiiiid."</sid>\n";
echo "<name>".$sotname."</name>\n";
echo "<selected>".$isseed."</selected>\n";
echo "</count>\n";
$rst->Movenext();
}
echo "</sort>";
2 JSP版的
//显示XML
response.addHeader("Content-Type","text/xml");
String xxx="";
xxx+="<?xml version=\"1.0\" encoding=\"gb2312\"?>\n";
xxx+="<book>\n";
xxx+="<count>\n";
xxx+="<uname>"+uname+"</uname>\n";
xxx+="<rname>"+rname+"</rname>\n";
xxx+="<nbank>"+nbank+"</nbank>\n";
xxx+="<djsmn>"+jsuan+"</djsmn>\n";
xxx+="<dbnob>"+dbnob+"</dbnob>\n";
xxx+="<suces>no</suces>\n";
xxx+="</count>\n";
xxx+="</book>";
out.clearBuffer();
out.println(xxx);
变量自己控制
1 PHP的
if(!$iiiiiid=$_GET["st1"])$iiiiiid="1";
if(!$selectd=$_GET["st2"])$selectd="1";
$dbc = new AccessAdoCon();
$con = $dbc->connect;
$rst = @new COM("ADODB.RecordSet");
$sql ="select * from 产品二级分类 where upid=$iiiiiid";
$rst->Open($sql,$con,1,3);
header("Content-Type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"gb2312\"?>\n";
echo "<sort>\n";
while(!$rst->EOF){
$iiiiiid=$rst->Fields["uid"]->Value;
$sotname=$rst->Fields["name"]->Value;
if($selectd==$iiiiiid)$isseed="YES"; else $isseed="NO";
echo "<count>\n";
echo "<sid>".$iiiiiid."</sid>\n";
echo "<name>".$sotname."</name>\n";
echo "<selected>".$isseed."</selected>\n";
echo "</count>\n";
$rst->Movenext();
}
echo "</sort>";
2 JSP版的
//显示XML
response.addHeader("Content-Type","text/xml");
String xxx="";
xxx+="<?xml version=\"1.0\" encoding=\"gb2312\"?>\n";
xxx+="<book>\n";
xxx+="<count>\n";
xxx+="<uname>"+uname+"</uname>\n";
xxx+="<rname>"+rname+"</rname>\n";
xxx+="<nbank>"+nbank+"</nbank>\n";
xxx+="<djsmn>"+jsuan+"</djsmn>\n";
xxx+="<dbnob>"+dbnob+"</dbnob>\n";
xxx+="<suces>no</suces>\n";
xxx+="</count>\n";
xxx+="</book>";
out.clearBuffer();
out.println(xxx);
变量自己控制
展开全部
你可以拼接一个xml字符串,然后再前台处理,或者传json字符串,在处理。json和xml差不多,
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
protected void Page_Load(object sender, EventArgs e)
{
string WFDM = Request["WFDM"];
DataTable dt = WeiFaDaiMaService.SearchWeiFaDaiMaXinXi(WFDM.Trim());
if (dt.Rows.Count > 0)
{
this.writerXML(dt);
}
else
{
Response.Write("NoData");
}
}
/// <summary>
/// XML转换
/// </summary>
/// <param name="dt"> </param>
public void writerXML(DataTable dt)
{
XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Response.ContentEncoding);
writer.Formatting = Formatting.Indented;
writer.WriteStartDocument();
dt.WriteXml(writer);
writer.Flush();
Response.End();
writer.Close();
}
{
string WFDM = Request["WFDM"];
DataTable dt = WeiFaDaiMaService.SearchWeiFaDaiMaXinXi(WFDM.Trim());
if (dt.Rows.Count > 0)
{
this.writerXML(dt);
}
else
{
Response.Write("NoData");
}
}
/// <summary>
/// XML转换
/// </summary>
/// <param name="dt"> </param>
public void writerXML(DataTable dt)
{
XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Response.ContentEncoding);
writer.Formatting = Formatting.Indented;
writer.WriteStartDocument();
dt.WriteXml(writer);
writer.Flush();
Response.End();
writer.Close();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询