Note that there are some explanatory texts on larger screens.

plurals
  1. POautocomplete problems with serverside json
    text
    copied!<p>For some reason the script below is not working.</p> <p>This is the code I am using to generate the json data:</p> <pre><code>Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Response.Clear() Response.Write(generate_json_data()) Response.End() End Sub </code></pre> <p>This produces the following output on screen:</p> <pre><code>[ {id:0,value:"c++"}, {id:1,value:"java"}, {id:2,value:"php"}, {id:3,value:"coldfusion"}, {id:4,value:"javascript"}, {id:5,value:"asp"}, {id:6,value:"ruby"} ]; </code></pre> <p>This is the jquery I have so far, which does not seem to work. It does not give an error, when I type into the input field, nothing happens, when it should be displaying some of the data from the json data.</p> <pre><code>$("input").autocomplete({ source: "serverside_array.aspx", dataType: "json", select: function (event, ui) { $("#txtAllowSearch").val(ui.item.value); // display the selected text $("#txtAllowSearchID").val(ui.item.id); // save selected id to hidden input } }); </code></pre> <p>EDIT 1: The header from the developer tools in chromium 10</p> <pre><code>Request URL:http://intranet/test_array.aspx?term=j Request Method:GET Status Code:200 OK Request Headers Accept:application/json, text/javascript, */* Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3 Accept-Encoding:gzip,deflate,sdch Accept-Language:en-US,en;q=0.8 Connection:keep-alive Content-Type:application/x-www-form-urlencoded Host:intranet Referer:http://intranet/rights_stage_three.aspx User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.17 (KHTML, like Gecko) Chrome/10.0.652.0 Safari/534.17 X-Requested-With:XMLHttpRequest Query String Parameters term:j Response Headers Cache-Control:private Content-Length:204 Content-Type:application/json; charset=utf-8 Date:Thu, 27 Jan 2011 16:11:14 GMT Server:Microsoft-IIS/6.0 X-AspNet-Version:2.0.50727 X-Powered-By:ASP.NET </code></pre> <p>EDIT 2: looking at the reponse data XHR, I get the following</p> <blockquote> <p>name test_array.aspx</p> <p>method get</p> <p>status 200 ok</p> <p>type application/json</p> <p>size 204b</p> <p>time pending</p> </blockquote> <p>EDIT 3:</p> <p>Now I am totally confused. I got it working by simply changing the contenttype generated by the aspx page to:</p> <pre><code>text/xml </code></pre> <p>instead of </p> <pre><code>applicaiton/json </code></pre> <p>why does it work with text/xml when I am returning json?</p>
 

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