我是Ajax的新手。我希望在付款处理后从商家网站检索交易详情。我的ajax调用脚本无效。请帮忙。
C#方法
public class RetrieveCache
{
[WebMethod]
public string RetrieveTransactionData(string ID)
{
ChannelFactory<ServiceSoap> PayChannelFactory = new ChannelFactory<ServiceSoap>("ServiceSoap12");
ServiceSoap Paychannel = PayChannelFactory.CreateChannel();
XmlNode node = Paychannel.RetrieveCachedData(ID);
return node.InnerXml;
}
}
Ajax调用HTML页面中的脚本来调用上面的c#方法
Html Page URL: http://localhost:55014/SuccessPage.html?id=29473740923
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
var url = window.location.search;
debugger;
var token = (url.replace("?", "").split("=")[1]).toString();
debugger;
var dataval = JSON.stringify({ token: token });
$.ajax({
url: "http://localhost:55014/RetrieveCache.cs/RetrieveTransactionData",
type: 'post',
data: JSON.stringify({ token: token }),
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function(data){
alert(data);
},
error: function (err) {
alert(err)
}
});
});
</script>