度日jquery.ajax XML数据 [英] get xml data by jquery.ajax

查看:121
本文介绍了度日jquery.ajax XML数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

剧本

  $.ajax({
    type: "post",
    url: "Default.aspx?cmd=Setting",
    success: parseXml
  });

function parseXml(xml)
{
   alert(xml);//show Full XML File
  //find every Tutorial and print the author
  $(xml).find("Tutorial").each(function()
  {
    $("#a").append($(this).attr("author") + "<br />");
  });
 }

HTML

<div id="a"></div>

code

protected void Page_Load(object sender, EventArgs e)
{
    if (Request["cmd"] == "Setting")
    {
        string k=@"<?xml version='1.0' encoding='utf-8' ?>
        <RecentTutorials>
        <Tutorial author='The Reddest'>
        <Title>Silverlight and the Netflix API</Title>
        <Categories>
              <Category>Tutorials</Category>
              <Category>Silverlight 2.0</Category>
              <Category>Silverlight</Category>
              <Category>C#</Category>
              <Category>XAML</Category>
        </Categories>
        <Date>1/13/2009</Date>
        </Tutorial>
        </RecentTutorials>";

          Response.Write(k );
          Response.End();
    }
}

我是一个初学者。

I am a beginner.

这是行不通的。

而警报(XML)显示XML文件。

while alert(xml) show xml File.

推荐答案

设置才能有jQuery的自动解析XML服务器上的适当的内容类型:

Set the proper content type on your server in order to have jQuery automatically parse the XML:

Response.ContentType = "text/xml";
Response.Write(k);
Response.End();

此外,你可以设置数据类型:XML,但如果你的服务器配置正确发送正确的内容类型是没有必要

Additionally you could set dataType: 'xml' but that's not necessary if your server is properly configured to send the correct content type.

下面是一个现场演示

这篇关于度日jquery.ajax XML数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆