jquery autocomplete to fill a javascript array? -
i wanted add together autocomplete text box had on form. found first-class thread entailed right here: http://stackoverflow.com/a/5973017/168703 needed because showed autocomplete when typed @
symbol.
it effect of this:
$("#ucaddactionitemissueactions_txtactionitem") // don't navigate away field on tab when selecting item .bind("keydown", function(event) { if (event.keycode === $.ui.keycode.tab && $(this).data("autocomplete").menu.active) { event.preventdefault(); } }).autocomplete({ minlength: 0, source: function(request, response) { var term = request.term, results = []; if (term.indexof("@") >= 0) { term = extractlast(request.term); if (term.length > 0) { results = $.ui.autocomplete.filter( availabletags, term); } else { results = ['start typing...']; } } response(results); }, focus: function() { // prevent value inserted on focus homecoming false; }, select: function(event, ui) { var terms = split(this.value); // remove current input terms.pop(); // add together selected item terms.push(ui.item.value); var email = getemail(ui.item.value); email = email + ";"; emails.push(email); $("#ucaddactionitemissueactions_hdnemails").val(emails.join("")); // add together placeholder comma-and-space @ end terms.push(""); this.value = terms.join(""); homecoming false; } });
pay close attending source
portion forced me declare this:
var availabletags = [ "jdoe", "tsmith", "mrighty", "tstevens", "ktripp", "tram", ];
that autocomplete suggestions within of js file...but part did not want. have load info database. unfortunately dealing ancient .net framework prolly pre 2.0 app. vb.net , there no linq or lists or stuff. fine thought..i create .asmx
file added strings array list, converted string array , returned in .asmx file. effect (this test no pulling info yet database):
imports system.web.services imports system.collections <system.web.services.webservice(namespace := "http://tempuri.org/myapp.com/getlogins")> _ public class getlogins inherits system.web.services.webservice #region " web services designer generated code " public sub new() mybase.new() 'this phone call required web services designer. initializecomponent() 'add own initialization code after initializecomponent() phone call end sub 'required web services designer private components system.componentmodel.icontainer 'note: next procedure required web services designer 'it can modified using web services designer. 'do not modify using code editor. <system.diagnostics.debuggerstepthrough()> private sub initializecomponent() components = new system.componentmodel.container() end sub protected overloads overrides sub dispose(byval disposing boolean) 'codegen: procedure required web services designer 'do not modify using code editor. if disposing if not (components nothing) components.dispose() end if end if mybase.dispose(disposing) end sub #end part ' web service illustration ' helloworld() illustration service returns string hello world. ' build, uncomment next lines save , build project. ' test web service, ensure .asmx file start page ' , press f5. ' 'public function helloworld() string ' homecoming "hello world" 'end function <webmethod()> _ public function getlogins() string() dim mylist arraylist mylist.add("jstevens") mylist.add("jdoe") dim arr() string = ctype(mylist.toarray(type.gettype("system.string")), string()) homecoming arr end function end class
as mentioned test i'm adding 2 items in string array , returning it. pretty unsure how alter jquery code incorporate this.... thought add together this:
$.ajax({ url: "getlogins.asmx/getlogins", data: "{ 'resname': '" + request.term + "' }", datatype: "json", type= "post", contenttype: "application/json; charset=utf-8" })
but not sure how incorporate in original jquery jquery skills zilch... can help me understand , set may work. 1 time test working can modify pull info database. on right path?
edit
here's have
$("#ucaddactionitemissueactions_txtactionitem") // don't navigate away field on tab when selecting item .bind("keydown", function(event) { if (event.keycode === $.ui.keycode.tab && $(this).data("autocomplete").menu.active) { event.preventdefault(); } }).autocomplete({ minlength: 0, source: function (request, response) { //get client value var c = $("#ucaddactionitemissueactions_ddlclientassignto").val(); var params= '{"clientid":"' + c + '"}'; $.ajax({ url: "getlogins.asmx/getlogins", data: params, datatype: "json", type: "post", contenttype: "application/json; charset=utf-8", datafilter: function (data) { homecoming data; }, success: function (data) { response($.map(data.d, function (item) { homecoming { value: item.name } })) }, error: function (xmlhttprequest, textstatus, errorthrown) { alert(textstatus); } });}, focus: function() { // prevent value inserted on focus homecoming false; }, select: function(event, ui) { var terms = split(this.value); // remove current input terms.pop(); // add together selected item terms.push(ui.item.value); var email = getemail(ui.item.value); email = email + ";"; emails.push(email); $("#ucaddactionitemissueactions_hdnemails").val(emails.join("")); // add together placeholder comma-and-space @ end terms.push(""); this.value = terms.join(""); homecoming false; } });
but app throwing internal server error 500. next exception:
system.invalidoperationexception: request format invalid: application/json; charset=utf-8. @ system.web.services.protocols.httpserverprotocol.readparameters() @ system.web.services.protocols.webservicehandler.invoke() @ system.web.services.protocols.webservicehandler.coreprocessrequest()
here webservice:
imports system.web.services imports system.collections <system.web.services.webservice(namespace := "http://tempuri.org/quikfix.jakah.com/getlogins")> _ public class getlogins inherits system.web.services.webservice <webmethod()> _ public function getlogins(byval clientid integer) string() dim mylist new arraylist mylist.add("jstevens") mylist.add("jdoe") mylist.add("smartin") dim arr() string = ctype(mylist.toarray(type.gettype("system.string")), string()) homecoming arr end function end class
again old 1.1 .net application, need in web config file represent .asmx file? parameters in web method match parameters of ajax phone call causing this?
i think problem here web services expect xml or text. json won't work.
you can seek changing content-type (in ajax call) text , returning string instead of string array getlogins method. way can serialize string array json string using json converter , homecoming that.
javascript jquery asp.net
No comments:
Post a Comment