$(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")); } }); });
我的问题是我取回了一些数据,但似乎无法显示它。
dataType应该是您收到的内容的类型,但contentType应该是您要发送的内容的哑剧类型,以下应该可以:
dataType
contentType
$(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")); } }); });