我需要从服务器获取 xml 文档,然后客户端对其进行签名并将其发送回服务器。
在服务器端,我有保存文档的网络方法:
[WebMethod]
public static void SaveSignedDocument(string SignedData)
{
SignedCms signedCms = new SignedCms();
....
}
然后,我从服务器获取文档,成功接收后,我让客户端对其进行签名并发回。这是Javascript
// get xml to sign
$.ajax({
type: "POST",
url: "Default.aspx/GetXMLReceipt",
data: "{'ITN': " + ITN + " }",
contentType: "application/json; charset=utf-8",
dataType: "xml",
success: function (xml) {
// xml file was got
var xmlString = xmlToString(xmlData);
// Sign data
var SignedData = SignData(xmlString);
// Send it to server
$.ajax({
url: 'Default.aspx/SaveSignedDocument',
data: "{ 'SignedData': '" + SignedData + "' }",
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data){
alert('Document was successfully sent!');
}
error: function (data, status, jqXHR) {
alert('Send signed data failed - ' + jqXHR);
}
});
},
error: function (data, status, jqXHR) {
alert('Get data failed - ' + jqXHR);
}
});
问题是第二个请求的警报都不会触发。如果我将请求更改为同步,一切都很好,但为什么它不像上面写的那样工作?服务器什么也没收到,如果我们查看网络流量,我发现请求被中断了。为什么?