Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery autocomplete not works with remote data from ashx
    primarykey
    data
    text
    <p>I use a jQuery autocomplete with an ASHX as source. But every request throws an error with number 200.</p> <p>My JavaScript:</p> <pre><code>$(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); } }); } }); }); </code></pre> <p>The HTML:</p> <pre><code>&lt;div id="username"&gt; &lt;asp:Label Text="User name" runat="server" /&gt; &lt;asp:TextBox ID="txtUserName" runat="server" /&gt; &lt;/div&gt; </code></pre> <p>ASHX:</p> <pre><code>Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest context.Response.Clear() context.Response.ContentType = "application/json" Try Dim oList As New List(Of ResultItem) For Each File As System.IO.FileInfo In New System.IO.DirectoryInfo(ApplicationInfo.Settings.AbsoluteUserConfigPath).GetFiles(context.Request.QueryString("term") &amp; "*.xml") oList.Add(New ResultItem With {.Value = System.Text.RegularExpressions.Regex.Replace(File.Name, File.Extension &amp; "$", String.Empty)}) Next context.Response.Write(New System.Web.Script.Serialization.JavaScriptSerializer().Serialize(oList)) Catch ex As Exception context.Response.Clear() context.Response.ContentType = "text/plain" context.Response.StatusCode = 500 context.Response.StatusDescription = ex.Message End Try End Sub </code></pre> <p>With static content it works fine but with this request I get the following error: <code>SyntaxError: JSON.parse: unexpected character</code>.</p> <p>The resulting JSON looks like</p> <pre><code>[ {"Value":"Item 1","Name":"","Description":""}, {"Value":"Item 2","Name":"","Description":""}, {"Value":"Item 3","Name":"","Description":""}, {"Value":"Item 4","Name":"","Description":""} ] </code></pre> <p>and should be valid.</p> <p>Any idea why it does not work? What is the unexpected character?</p> <p>Thanks for any response.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload