There are two methods GetUserAssignedSystems() and GetUserAssignedSystems(string Id)
These methods act very differently from each other. The problem is, when I want to call GetUserAssignedSystems(string Id), the parameter-less method 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 making the 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 being ignored?
UPDATE
Here is the code for the 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
});
}
Javascript does not support overloaded functions (multiple functions with the same name that accept different parameters) in the same way that some languages do. If you need it to optionally perform tasks based on the presence of an input parameter you have to add checking within the function that determines if the variable was passed
if ( param == undefined) {}and then behave in the appropriate way based on the presence or absence of said variable. Redefining the function twice with different parameters won’t work.Per updates, try changing your call like so:
Essentially you were passing a string, not an object to the jQuery $.ajax method, which was probably preventing your values from reaching the server properly. Let me know how that behaves.