I invoke a WebService method via jQuery
.js code
$.ajax({
url: '/ms.asmx/se2',
data: {},
success: function (result) {
aler开发者_JAVA百科t(result);
},
dataType: 'text'
});
.asmx method
[WebMethod]
public string se2()
{
return "OK";
}
the result is
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">OK</string>
How to show only that XML content - OK
- instead the XML code ?
jQuery has a function to parse XML: $.parseXML
(http://api.jquery.com/jQuery.parseXML/). In addition, if you pass 'xml' to dataType
, jQuery will automatically parse it as xml.
So:
$.ajax({
url: '/ms.asmx/se2',
data: {},
success: function (result) {
alert( $(result).find('string').text() );
}
dataType: 'xml'
});
精彩评论