开发者

jQuery Post not getting a xml response

开发者 https://www.devze.com 2023-03-14 05:02 出处:网络
Here is my jQuery post request, how can i get back xml response, I checked in fiddler the response is coming as my expected xml

Here is my jQuery post request, how can i get back xml response, I checked in fiddler the response is coming as my expected xml

Here is my jquery post

$.post("/csm/viewall.action",
  { sessiontoken:   sessiontoken },
      function(xml)
      {
            alert(xml);
      }
);

alert returns [object XMLDocument]

My xml

<list>
<com.abc.db.ConfigInfo>
<cfgId>83</cfgId>
<cfgName>test</cfgName>
<cfgDesc>test</cfgDesc>
<cfgType>test</cfgType>
<fileName>csmclientbenz.xml</fileName>
<absolutePath>../webapps/csm/files//1-105101/csmclientbenz.xml</absolutePath>
</com.abc.db.ConfigInfo>
<com.abc.db.ConfigInfo>
<cfgId>82</cfgId>
<cfgName>test1</cfgName>
<cf开发者_StackOverflow社区gDesc>test2</cfgDesc>
<cfgType>test1</cfgType>
<fileName>csmclientbenz.xml</fileName>
<absolutePath>../webapps/csm/files//1-105101/csmclientbenz.xml</absolutePath>
</com.abc.db.ConfigInfo>
<list>


here is an informative post about parsing the xml with jquery

http://www.switchonthecode.com/tutorials/xml-parsing-with-jquery

you can read the xml as

$(xml).find('com.abc.db.ConfigInfo').each(function(){
var ths = $(this);
var id= ths.find('cfgId').text();
var name = ths.find('cfgName').text();
....//and so on

});


You are getting the XML back. It's in the form of an XMLDocument object.

You can then use jQuery(xml) to create a jQuery object that you can go on to manipulate with the standard jQuery methods.


Change your line of code to this:

alert($(xml).find('list').html());


It is failing try to catch the success event and error event with:

var jqxhr = $.post("example.php", function() {
  alert("success");
})
.success(function() { alert("second success"); })
.error(function() { alert("error"); })
.complete(function() { alert("complete"); });
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号