Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么jqueryajax调用C#web方法不起作用_C#_Javascript_Jquery_Ajax_Asmx - Fatal编程技术网

为什么jqueryajax调用C#web方法不起作用

为什么jqueryajax调用C#web方法不起作用,c#,javascript,jquery,ajax,asmx,C#,Javascript,Jquery,Ajax,Asmx,这是我的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')

这是我的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");
        }
    });
}
这是我的Web服务:

//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、DocID和dataString是正确的。我认为我的Web方法签名的设置方式有问题,因为Ajax从未被触发过。当单步执行.ajax方法时,会出现错误,而不是成功。

您的web方法需要一个参数,即您已经拥有的数据对象,但由于您直接传递对象,因此您要传递多个参数

相反,您需要有一个具有一个属性的对象,
dataString
,该属性的值应该是您的对象,如下所示:

var dataString = JSON.stringify({ dataString: dataObj });
                                    ▲--should match--▼
public WebMethodResult declassify(DeclassifyType dataString)

您的web方法需要一个参数,即您已经拥有的数据对象,但由于您直接传递对象,因此您要传递多个参数

相反,您需要有一个具有一个属性的对象,
dataString
,该属性的值应该是您的对象,如下所示:

var dataString = JSON.stringify({ dataString: dataObj });
                                    ▲--should match--▼
public WebMethodResult declassify(DeclassifyType dataString)
啊,我刚修好,

刚把签名改成

[WebMethod(EnableSession = true)]
public WebMethodResult declassify(int batchId, string[] docIds)
{
}
真的很简单。谢谢你查看我的帖子

啊,我刚修好

刚把签名改成

[WebMethod(EnableSession = true)]
public WebMethodResult declassify(int batchId, string[] docIds)
{
}

真的很简单。谢谢你查看我的帖子

当你说“不工作”时,流程的哪一部分不工作?你期望发生什么?您会收到哪些错误消息(如果有)?您是否尝试过使用或类似工具进行调试?请编辑您的问题并提供更多详细信息。
declassifyAjax
是否曾被激发?如果在其中放入alert(),会发生什么?当您说“不工作”时,流程的哪一部分不工作?你期望发生什么?您会收到哪些错误消息(如果有)?您是否尝试过使用或类似工具进行调试?请编辑您的问题并提供更多详细信息。
declassifyAjax
是否曾被激发?如果在其中放入alert()会发生什么?