views:

38

answers:

2

Here is my 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");
        }
    });
}

And here is my Web Service:

//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)
    {
    }

Any and all help appreciated!

Debugging in Firebug shows that the variables dataObj, batchId, docIds and dataString are correct. There is something wrong with the way my Web Method signature is setup I think, because the Ajax is never fired off. When stepping through the .ajax method, it goes to error, not success.

+2  A: 

Your web methods expects one parameter, the data object you already have, but you're passing multiple parameters since you're passing the object directly.

Instead, you need to have an object with one property, dataString, and that property's value should be your object, like this:

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

Ah, I just fixed it,

just changed the signature to

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

Simple really. Thanks for checking my post!

shaw2thefloor