gpt4 book ai didi

c# - 为什么对 C# Web 方法的 jQuery ajax 调用不起作用

转载 作者:行者123 更新时间:2023-11-30 23:43:08 25 4
gpt4 key购买 nike

这是我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com