有兩種方法GetUserAssignedSystems()
和GetUserAssignedSystems(string Id)
這些方法的行爲彼此非常不同。問題是,當我想調用GetUserAssignedSystems(string Id)
時,調用無參數方法。兩種方法具有不同的簽名,jquery沒有調用正確的方法
這裏是方法:
[WebMethod]
[ScriptMethod]
public IEnumerable GetUserAssignedSystems(string cacId)
{
return Data.UserManager.GetUserAssingedSystems(cacId);
}
[WebMethod]
[ScriptMethod]
public IEnumerable GetUserAssignedSystems()
{
//do something else
}
這裏是jQuery的進行調用:
CallMfttService("ServiceLayer/UserManager.asmx/GetUserAssignedSystems",
"{'cacId':'" + $('#EditUserCacId').val() + "'}", function(result) {
for (var userSystem in result.d) {
$('input[UserSystemID=' + result.d[userSystem] + ']').attr(
'checked', 'true');
}
});
爲什麼被忽略此方法的任何想法?
UPDATE
下面是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
});
}代碼
謝謝!我沒有意識到你不能有重載的方法。當我註釋掉無參數方法時,一切都很完美。再次感謝! – Avien 2010-06-15 16:19:04
當然!樂意效勞。 – 2010-06-15 16:21:07
@ g.d.d.c。但似乎沒有調用正確的功能發生在C#級別,而不是JS。我不確定刪除其他功能是否解決了問題,或者僅僅是掩蓋了它。 – 2010-06-15 16:26:08