vb.net - jQuery autocomplete not works with remote data from ashx -


i use jquery autocomplete ashx source. every request throws error number 200.

my javascript:

$(function () {     $('#username input[type = "text"]').autocomplete({         source: function (request, response) {             $.ajax({                 url: "username.ashx?term=" + request.term,                 datatype: "json",                 type: "post",                 success: function (data) {                     response($.map(data, function (item) {                         return {                             label: item.value                         }                     }))                 },                 error: function (xhr, ajaxoptions, thrownerror) {                     alert(xhr.status);                     alert(thrownerror);                 }             });         }     }); }); 

the html:

<div id="username">     <asp:label text="user name" runat="server" />     <asp:textbox id="txtusername" runat="server" /> </div> 

ashx:

public sub processrequest(byval context httpcontext) implements ihttphandler.processrequest     context.response.clear()     context.response.contenttype = "application/json"      try         dim olist new list(of resultitem)          each file system.io.fileinfo in new system.io.directoryinfo(applicationinfo.settings.absoluteuserconfigpath).getfiles(context.request.querystring("term") & "*.xml")             olist.add(new resultitem {.value = system.text.regularexpressions.regex.replace(file.name, file.extension & "$", string.empty)})         next          context.response.write(new system.web.script.serialization.javascriptserializer().serialize(olist))     catch ex exception         context.response.clear()         context.response.contenttype = "text/plain"         context.response.statuscode = 500         context.response.statusdescription = ex.message     end try end sub 

with static content works fine request following error: syntaxerror: json.parse: unexpected character.

the resulting json looks like

[     {"value":"item 1","name":"","description":""},     {"value":"item 2","name":"","description":""},     {"value":"item 3","name":"","description":""},     {"value":"item 4","name":"","description":""} ] 

and should valid.

any idea why not work? unexpected character?

thanks response.

i changed source , json , works it.

$(function () {     $('#username input[type = "text"]').autocomplete({         source: "username.ashx"     }); } 
[     {"object":"item 1","label":"","description":""},     {"object":"item 2","label":"","description":""},     {"object":"item 3","label":"","description":""},     {"object":"item 4","label":"","description":""} ] 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -