这是我的 JS:
function declassifyAjax(e) {
var items = getSelected();
var docIds = new Array();
items.each(get);
//get ids of QcItem/docId we are dealing with
function get(count, el) {
docIds[count] = $(el).parent().attr('id');
}
var dataObj = new Object();
dataObj.batchId = batchId;
dataObj.docIds = docIds;
var dataString = JSON.stringify(dataObj)
//make call to webservice to get html to recreate view showing
//pending declassification
$.ajax({
type: "POST",
url: applicationRoot + 'Models/BatchQC.asmx/declassify',
data: dataString,
contentType: "application/json; charset=utf-8",
success: function (data) {
if (ProcessWebMethodResult.processWebMethodResult(data) == true) {
declassifyProcess(data, e);
}
},
error: function (e) {
alert("Failed to Get declassification details");
}
});
}
这是我的网络服务:
//type to represent the input the declassify method
public class DeclassifyType
{
public int batchId;
public string[] docIds;
}
[WebMethod(EnableSession = true)]
public WebMethodResult declassify(DeclassifyType dataString)
{
}
感谢任何和所有帮助!
在Firebug中调试显示变量dataObj、batchId、docIds和dataString是正确的。我认为我的 Web 方法签名设置方式有问题,因为 Ajax 从未被触发。单步执行 .ajax 方法时,会出错,而不是成功。
最佳答案
您的 Web 方法需要一个参数,即您已有的数据对象,但由于您直接传递该对象,所以您要传递多个参数。
相反,您需要一个具有一个属性 dataString
的对象,并且该属性的值应该是您的对象,如下所示:
var dataString = JSON.stringify({ dataString: dataObj });
▲--should match--▼
public WebMethodResult declassify(DeclassifyType dataString)
关于c# - 为什么对 C# Web 方法的 jQuery ajax 调用不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3986217/