Two methods with different signatures, jquery does not call the correct method

There are two methods GetUserAssignedSystems()and GetUserAssignedSystems(string Id) these methods operate completely different from each other. The problem is that when I want to call GetUserAssignedSystems(string Id), the method without the parameter is called.

Here are the methods:

[WebMethod]
[ScriptMethod]
public IEnumerable GetUserAssignedSystems(string cacId)
{
    return Data.UserManager.GetUserAssingedSystems(cacId);
}

[WebMethod]
[ScriptMethod]
public IEnumerable GetUserAssignedSystems()
{
    //do something else
}

Here is the jQuery call:

CallMfttService("ServiceLayer/UserManager.asmx/GetUserAssignedSystems", 
        "{'cacId':'" + $('#EditUserCacId').val() + "'}", function(result) {
            for (var userSystem in result.d) {
                $('input[UserSystemID=' + result.d[userSystem] + ']').attr(
                    'checked', 'true');
            }
        });

Any ideas why this method is ignored?

UPDATE

Here is the code for CallMfttService

function CallMfttService(method, jsonParameters, successCallback, errorCallback){
if (errorCallback == undefined)
{
    errorCallback = function(xhr)
    {
        if (xhr.status == 501)
        {
            alert(xhr.statusText);
        }
        else
        {
            alert("Unexpected Error");
        }
    }
}

$.ajax({
    type: "POST",
    url: method,
    data: jsonParameters,
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: successCallback,
    error: errorCallback
});

}

+3
source share
3 answers

Javascript ( , ) , . , , , , if ( param == undefined) {}, , .

, :

CallMfttService("ServiceLayer/UserManager.asmx/GetUserAssignedSystems", 
    {'cacId': $('#EditUserCacId').val() }, function(result) {
        for (var userSystem in result.d) {
            $('input[UserSystemID=' + result.d[userSystem] + ']').attr(
                'checked', 'true');
        }
    });

, , jQuery $.ajax, , , . , .

+4

, JSON . JSON ... JSON :

 CallMfttService("ServiceLayer/UserManager.asmx/GetUserAssignedSystems", '{"cacId":"' + $('#EditUserCacId').val() + '"}', function(result) {

, CallMfttService, , :

CallMfttService("ServiceLayer/UserManager.asmx/GetUserAssignedSystems", {cacId:   $('#EditUserCacId').val()}, function(result) {
0

, # WebMethod . " ". - ( , , , - ), WebMethod . . # WebMethod , , , .

0

Source: https://habr.com/ru/post/1750147/


All Articles