6
$(document).ready(function() {
        $.ajax({ type: "POST",
                        url: "/getprojects.ashx",
                        data: "<formData client=\"\" year=\"\" categories=\"\" tags=\"\" freeText=\"\" count=\"34\" page=\"1\"></formData>",
                        dataType: "text/xml",
                        cache: false,
                        error: function() { alert("No data found."); },
                        success: function(xml) {
                            alert("it works");
                            alert($(xml).find("project")[0].attr("id"));
                        }
        });
    });

我的问题是我得到了一些数据,但我似乎无法显示它。

4

2 回答 2

10

dataType应该是您收到的类型,但contentType应该是您发送的 mime 类型,以下应该没问题:

$(document).ready(function() {
        $.ajax({ type: "POST",
                        url: "/getprojects.ashx",
                        data: "<formData client=\"\" year=\"\" categories=\"\" tags=\"\" freeText=\"\" count=\"34\" page=\"1\"></formData>",
                        contentType: "text/xml",
                        dataType: "xml",
                        cache: false,
                        error: function() { alert("No data found."); },
                        success: function(xml) {
                            alert("it works");
                            alert($(xml).find("project")[0].attr("id"));
                        }
        });
    });
于 2010-06-23T07:20:42.473 回答
2

你的dataType好像错了。它应该看起来像

dataType: "xml"

你的data结构看起来也很奇怪。看看.serializeArray()。它应该是标准查询字符串foo=bar&test=bla等。

如果success handler执行,请尝试查找您的xml变量plain,而不是对其进行操作.find()或其他任何操作。还是空的?

于 2010-06-23T06:42:50.537 回答