title: Not getting the ASP response to work with JQuery AutoComplete
body: <p>This is driving me nuts. I've tried solving this two days already browsing through many webpages.</p>
  
  <p>I'd like to use the jquery-ui autocomplete functionality just exactly as the sample in <a href="http://jqueryui.com/resources/demos/autocomplete/remote-jsonp.html" rel="nofollow noreferrer">http://jqueryui.com/resources/demos/autocomplete/remote-jsonp.html</a>, but instead of calling search.php I need to call an ASP file (Microsoft IIS environment). So, I created a local copy of above mentioned HTML file and adjusted only the URL.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(function() {
    function log(message) {
      $("&lt;div&gt;").text(message).prependTo("#log");
      $("#log").scrollTop(0);
    }
  
    $("#birds").autocomplete({
      source: function(request, response) {
        $.ajax({
          url: "http://jqueryui.com/resources/demos/autocomplete/search.php",
          dataType: "jsonp",
          data: {
            term: request.term
          },
          success: function(data) {
            response(data);
          }
        });
      },
      minLength: 2,
      select: function(event, ui) {
        log("Selected: " + ui.item.value + " aka " + ui.item.id);
      }
    });
  });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.ui-autocomplete-loading {
    background: white url("http://jqueryui.com/resources/demos/autocomplete/images/ui-anim_basic_16x16.gif") right center no-repeat;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;meta charset="utf-8"&gt;
  &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
  &lt;title&gt;jQuery UI Autocomplete - Remote JSONP datasource&lt;/title&gt;
  &lt;link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"&gt;
  &lt;link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css"&gt;
  &lt;script src="https://code.jquery.com/jquery-1.12.4.js"&gt;&lt;/script&gt;
  &lt;script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"&gt;&lt;/script&gt;
  
  &lt;body&gt;
  
    &lt;div class="ui-widget"&gt;
      &lt;label for="birds"&gt;Birds: &lt;/label&gt;
      &lt;input id="birds"&gt;
    &lt;/div&gt;
  
    &lt;div class="ui-widget" style="margin-top:2em; font-family:Arial"&gt;
      Result:
      &lt;div id="log" style="height: 200px; width: 300px; overflow: auto;" class="ui-widget-content"&gt;&lt;/div&gt;
    &lt;/div&gt;
  
  
  &lt;/body&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <ul>
  <li>Now, when I set URL to search.php of jquery.com (cross-domain, from my web server to the file which is also used by the original HTML) it works a bit slow, but fine</li>
  <li>When I try it with my local ASP file which is reading data from SQL it doesn't work although when I call the file directly in the browser it returns valid JSON data... I even changed the ASP file to do nothing than only a <code>Response.Write</code> with hard coded JSON data</li>
  <li>I also tried it with <code>Response.ContentType = "application/json"</code>, but this didn't help either</li>
  <li>Then I loaded an own search.php file which again only does a <code>echo</code> of some hardcoded JSON data to <a href="https://softd4u.ch/search.php" rel="nofollow noreferrer">https://softd4u.ch/search.php</a> and tried to call this, but again without success</li>
  </ul>
  
  <p>I found several samples in the Internet where the ASP file would be directly entered as source parameter (often older posts). I guess this might be working, but I think it makes sense to call the file via AJAX.</p>
  
  <p>Trying to debug the <em>jquery-1.12.4.js</em> I at least found out that there is a 'parseerror' returned at one point, but I have no idea why and what I should do differently. At <code>function ajaxHandleResponses( s, jqXHR, responses )</code> the variable responses was undefined in the case when it worked, but had content iin the case when it didn't work.</p>
  
  <p>I'm sure the files are actually called (checked logs etc.) but they never trigger the success function of the AJAX call.</p>
  
  <p>Does anyone have an idea what I'm missing here?</p>
  
  <p>Source of classic asp file - version 1 (DB connection etc. handled in inc file):</p>
  
  <pre><code>&lt;!-- #INCLUDE FILE="includes/general.inc" --&gt;
  
  &lt;% 
  Dim errortextInternal, rs, search, sql
  Dim coma
  
  search = Request.QueryString("term")
  sql = "SELECT TOP 20 itmId, itmNo, itmDescr1, itmDescr2, itmInact, CASE WHEN itsuSupId1 IS NULL THEN '' ELSE itsuSupId1 END AS SupId1, " &amp; _
          "CASE WHEN itsuSupId2 IS NULL THEN '' ELSE itsuSupId2 END AS SupId2, " &amp; _
          "CASE WHEN itsuSupId3 IS NULL THEN '' ELSE itsuSupId3 END AS SupId3 " &amp; _
          "FROM Items LEFT JOIN ItemsSuppl ON itmId = itsuItmId WHERE "
  sql = sql &amp; " (itmNo LIKE '%" &amp; search &amp; "%' OR itmDescr1 LIKE '%" &amp; search &amp; "%' OR itmDescr2 LIKE '%" &amp; search &amp; "%' OR EXISTS " &amp; _
              "(SELECT * FROM ItemsSuppl AS sub WHERE sub.itsuItmId = itmId AND (itsuSupId1 LIKE '%" &amp; search &amp; "%' OR itsuSupId2 LIKE '%" &amp; search &amp; "%' OR itsuSupId3 LIKE '%" &amp; search &amp; "%'))) ORDER BY itmNo, itmDescr1 "
  
  'Response.ContentType = "application/json"
  Response.Write("[")
  coma = ""
  
  Success = SelectDbRecords(errortextInternal, rs, sql)
  
  If Success Then
  
      Do While Not rs.EOF
          Response.Write(coma &amp; "{""id"":""" &amp; rs("itmId") &amp; """,""label"":""" &amp; Server.HTMLEncode(rs("itmNo") &amp; " - " &amp; Trim(Trim(rs("itmDescr1")) &amp; " " &amp; Trim(rs("itmDescr2")))) &amp; """,""value"":""" &amp; Server.HTMLEncode(rs("itmNo") &amp; " - " &amp; Trim(Trim(rs("itmDescr1")) &amp; " " &amp; Trim(rs("itmDescr2")))) &amp; """}") 
          If coma = "" Then
              coma = ","
          End If
          rs.MoveNext
      Loop
      rs.ActiveConnection.Close
  
  Else
      Response.Write("Fehler!")
  End If 
  
  Response.Write("]")
  
  %&gt;
  </code></pre>
  
  <p>Source of classic asp file - version 2 (hardcoded response for test purpose; no need to retrieve querystring):</p>
  
  <pre><code>&lt;%@LANGUAGE="VBSCRIPT"%&gt;
  &lt;%
  Response.Write("[{""id"":""Nycticorax nycticorax"",""label"":""Black-crowned Night Heron"",""value"":""Black-crowned Night Heron""},{""id"":""Ardea purpurea"",""label"":""Purple Heron"",""value"":""Purple Heron""},{""id"":""Tetrao tetrix"",""label"":""Black Grouse"",""value"":""Black Grouse""},{""id"":""Caprimulgus europaeus"",""label"":""European Nightjar"",""value"":""European Nightjar""},{""id"":""Picus viridis"",""label"":""European Green Woodpecker"",""value"":""European Green Woodpecker""},{""id"":""Saxicola rubicola"",""label"":""European Stonechat"",""value"":""European Stonechat""},{""id"":""Luscinia svecica"",""label"":""Bluethroat"",""value"":""Bluethroat""},{""id"":""Ardea cinerea"",""label"":""Grey Heron"",""value"":""Grey Heron""},{""id"":""Corvus cornix"",""label"":""Hooded Crow"",""value"":""Hooded Crow""},{""id"":""Sylvia curruca"",""label"":""Lesser Whitethroat"",""value"":""Lesser Whitethroat""},{""id"":""Pluvialis apricaria"",""label"":""European Golden Plover"",""value"":""European Golden Plover""},{""id"":""Sylvia communis"",""label"":""Common Whitethroat"",""value"":""Common Whitethroat""}]")
  %&gt;
  </code></pre>