Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 通过jquery.ajax获取xml数据_Asp.net_Xml_Jquery_Xmlhttprequest - Fatal编程技术网

Asp.net 通过jquery.ajax获取xml数据

Asp.net 通过jquery.ajax获取xml数据,asp.net,xml,jquery,xmlhttprequest,Asp.net,Xml,Jquery,Xmlhttprequest,剧本 $.ajax({ 类型:“post”, url:“Default.aspx?cmd=Setting”, 成功:parseXml }); 函数解析xml(xml) { 警报(xml);//显示完整的xml文件 //查找每个教程并打印作者 $(xml).find(“教程”).each(函数() { $(“#a”).append($(this.attr(“作者”)+”); }); } HTML 代码 受保护的无效页面加载(对象发送方,事件参数e) { 如果(请求[“cmd”]=“设置”)

剧本

$.ajax({
类型:“post”,
url:“Default.aspx?cmd=Setting”,
成功:parseXml
});
函数解析xml(xml)
{
警报(xml);//显示完整的xml文件
//查找每个教程并打印作者
$(xml).find(“教程”).each(函数()
{
$(“#a”).append($(this.attr(“作者”)+”
); }); }
HTML


代码

受保护的无效页面加载(对象发送方,事件参数e)
{
如果(请求[“cmd”]=“设置”)
{
字符串k=@“
Silverlight和Netflix API
教程
Silverlight 2.0
银光
C#
XAML
1/13/2009
";
回答:写(k);
Response.End();
}
}
我是初学者

这不管用


当警报(xml)显示xml文件时。

尝试将数据类型强制为xml:
数据类型:“xml”
尝试将数据类型强制为xml:
数据类型:“xml”
在服务器上设置适当的内容类型,以便jQuery自动解析xml:

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();
    }
}
此外,您可以设置
数据类型:“xml”
,但如果您的服务器正确配置为发送正确的内容类型,则不需要设置


下面是一个。

在服务器上设置适当的内容类型,以便jQuery自动解析XML:

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();
    }
}
此外,您可以设置
数据类型:“xml”
,但如果您的服务器正确配置为发送正确的内容类型,则不需要设置


这里有一个。

请定义“不起作用”。您是否尝试过
警报(xml)内部
parseXml
显示xml但不附加到div请定义“不工作”。您是否尝试了
警报(xml)内部
parseXml
显示xml,但不附加到div,因此应另外使用
Response.ContentType=“text/xml;charset=utf-8”
在服务器代码中,作为后续代码,还应使用
Response.ContentType=“text/xml;charset=utf-8”
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();
    }
}
Response.ContentType = "text/xml";
Response.Write(k);
Response.End();