![](/img/trans.png)
[英]html returns as xml when calling webservice (asmx) in jquery
[英]jQuery to ASMX webservice xml transfer
我需要一些幫助,我用谷歌搜索了幾個小時,我開始有點絕望了。 我需要使用方法創建asp.net asmx webservice,它將使用xml中的數據。 我的問題是,我不知道如何配置web服務和$.ajax()
有些人告訴我將xml編碼為字符串並在服務器上解碼它,但這對我來說不是很好的解決方案,因為webservice必須盡可能普及。 所以任何人都可以給我一些簡單的例子來說明$.ajax()
調用asmx webservice轉移,例如<xml attr='test'>test</xml>
在服務方面:
[WebMethod]
public void Foo(string xml)
{
... do something with the XML
}
在客戶端:
$.ajax({
url: 'bar.asmx/foo',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify({ xml: '<xml attr="test">test</xml>' }),
success: function(result) {
alert('The XML was successfully sent to the web service');
}
});
哦順便說一下,ASMX是一種非常棄用的技術。 您應該考慮使用WCF或Web API在.NET上開發服務器端Web服務。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.