Newbie here. I have an issue about Ajax. The situation is this: I have a multiselect dropdownlist of managements, and I want to bring the managers from those managements, and attach them on another dropdownlist (I did not finish that).
Here, I call the function and send the selected values:
getManagersByManagement($("#ddlManagement").val());
For now, I want this to return the data from GetManagers, on JsonGridDataProvider.svc.
function getManagersByManagement(managementIds) {
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: "../../JsonGridDataProvider.svc/GetManagers",
data: { 'Id': JSON.stringify(managementIds) },
dataType: "json",
success: function (data) {
$.jStorage.set($rpt.pageIdentifier + "-Managers", JSON.stringify(data));
alert($.jStorage.get($rpt.pageIdentifier + "-Managers"));
},
error: function (jqXhr, textStatus, errorThrown) {
alert("fail");
}
});
This is the GetManagers function >>
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json)]
public List GetManagers(long[] managementIds)
{
IList allUserList = (new UserBiz()).GetAllByUserByTypeAndState(2, 3);
List list = (from v in allUserList where v.Active == true orderby v.FullName ascending select v).ToList();
var finalUserList = (from item in list
let sameManList = (from v in item.Management
where managementIds.Contains(v.Id)
select v.Id).Distinct().ToList()
where sameManList.Count > 0
select item).ToList();
return finalUserList;
}
But when instead of going to the GetManagers function, it returns "error 401" ("Unauthorized"). Any idea why is this happening?
EDIT
Thank you all for your replies. Thanks to that, I checked the problem is not the javascript function nor the ajax configuration, but the GetManagers() function (or some configuration I'm missing). Any ideas?