在jquery中查看xml数据
如何使用jquery显示xml数据?我不需要解析它,我只需要在页面上向用户显示它 以下是我当前的代码:在jquery中查看xml数据,jquery,Jquery,如何使用jquery显示xml数据?我不需要解析它,我只需要在页面上向用户显示它 以下是我当前的代码: $.ajax({ type: "POST", dataType: "xml", contentType: "application/json; charset=utf-8", url: "Service2.svc/DoWork", data: "{}", processdata: true, success: function(respo
$.ajax({
type: "POST",
dataType: "xml",
contentType: "application/json; charset=utf-8",
url: "Service2.svc/DoWork",
data: "{}",
processdata: true,
success: function(response, textStatus, jqXHR) {
alert($(jqXHR).responseXML);
}); $("#Text1").val($(response));
}, error: function() {
alert("error");
}
});
由于<和>,我认为您无论如何都需要解析它。使用“加载”方法。我相信这会起作用:
$.ajax({
success: function(response, textStatus, jqXHR) {
alert(jqXHR.xml);
}
});
我假设您已经将响应XML存储到变量
XML
中
我认为这应该奏效:
alert($('<div>').append($(xml).clone()).remove().html());
alert($('').append($(xml.clone()).remove().html());
这里的功劳是:您可以使用结果。responseText
其中result是在complete函数中返回的对象。。如果我在alert方法中显示xml呢?我尝试了警报($(xml));但它只显示“object[object]”。有什么想法吗?请让我们看看你的代码。为什么在变量之前使用“$”字符?JavaScript不是Perl或PHP;)。因为jQuery函数
$()
在作为第一个参数传递时将HTML字符串(希望是XML)转换为jQuery对象。像这样:$('asd')代码>$.ajax({type:“POST”,数据类型:“xml”,contentType:“application/json;charset=utf-8”,url:“Service2.svc/DoWork”,数据:{}),processdata:true,//true或False成功:函数(响应,textStatus,jqXHR){alert($(jqXHR).responseXML);};$(“#Text1”).val($(response));},错误:函数(){alert(“error”);}
@user,发布你的jquery ajax代码,你想在哪里显示/