c# - how to call web service in ajax properly? -


ok, here trying do, want user active directory , put in list,so call web service ajax, user , put list string, , later on want use jquery autocomplete in textbox base on list of user got before.

this :

  $(document).ready(function () {              // load data initialize plugin:             $.ajax({                 url: '/svcaduser.asmx/getaduserlist',                 datatype: 'json'             }).done(function (source) {                  var countriesarray = $.map(source, function (value) { return { value: value }; }),                     countries = $.map(source, function (value) { return value; });                  // setup jquery ajax mock:                 $.mockjax({                     url: '*',                     responsetime: 200,                     response: function (settings) {                         var query = settings.data.query,                             querylowercase = query.tolowercase(),                             suggestions = $.grep(countries, function (country) {                                 return country.tolowercase().indexof(querylowercase) !== -1;                             }),                             response = {                                 query: query,                                 suggestions: suggestions                             };                          this.responsetext = json.stringify(response);                     }                 });                    // initialize autocomplete local lookup:                 $('#mainct_dtvjobvac_pic').autocomplete({                     lookup: countriesarray,                     onselect: function (suggestion) {                         $('#selection').html('you selected: ' + suggestion.value + ', ' + suggestion.data);                     }                 });              });          }());      }()); 

but throw me error, "networkerror: 500 internal server error - http://localhost:60525/svcaduser.asmx/getaduserlist", if change url svcaduser.asmx, not give error, give me no result.

what wrong here? btw here web service code :

 [webservice(namespace = "http://tempuri.org/")]     [webservicebinding(conformsto = wsiprofiles.basicprofile1_1)]     [system.componentmodel.toolboxitem(false)]     // allow web service called script, using asp.net ajax, uncomment following line.      [system.web.script.services.scriptservice]     public class svcaduser : system.web.services.webservice     {         [scriptmethod(responseformat = responseformat.json)]         [webmethod]         public list<string> getaduserlist(string keyword)         {             list<string> alluser = new list<string>();              using (var context = new principalcontext(contexttype.domain, "weekendinc.com"))             {                 using (var searcher = new principalsearcher(new userprincipal(context)))                 {                     foreach (var result in searcher.findall())                     {                         directoryentry de = result.getunderlyingobject() directoryentry;                          alluser.add((string)de.properties["samaccountname"].value);                     }                 }             }              var filtereduser = alluser.where(usr => usr.tolower().startswith(keyword.tolower()));              return filtereduser.tolist();         }      } 

try this

jquery.ajax({             type: 'post',             contenttype: 'application/json;',             data: '{keyword:"test"}',             datatype: 'json',             async: true,             url: 'svcaduser.asmx/getaduserlist',             success: function (result) {                 alert(result.d);             }         }); 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -