1

I am trying to populate auto complete list by typing on textbox using jquery AJAX:

This is my code:

$("#formLoc").keyup(function(event){
    var keyword = $("#formLoc").val();
        if(keyword.length){
            if(event.keyCode != 40 && event.keyCode != 38 && event.keyCode != 13){
                $.ajax({
                    'type':'GET',
                    'url': 'AIR_NAME_SEARCH_2.ASP',
                    data: "locKeyword="+keyword,
                    success: function(responseText){
                        alert(responseText);
                        if(responseText != 0){
                            $(".ajax_response").fadeIn("slow").html(msg);
                        }else{
                            $(".ajax_response").fadeIn("slow"); 
                            $(".ajax_response").html('<div style="text-align:left;">No station found!</div>');
                        }
                    }
            });
        }
});

AIR_NAME_SEARCH_2.ASP

<% @LANGUAGE="VBSCRIPT" CODEPAGE="65001" %>
<!--#include file="include/dataconn2.asp"-->


<%
set AIR=Server.CreateObject("ADODB.Recordset")
AIR.Open "select * from AIR_AIRPORT_INDIA WHERE AIRPORT_CODE = '" + Request.QueryString("locKeyword") + "' OR AIRPORT LIKE '" + Request.QueryString("locKeyword") + "%' ORDER BY AIRPORT",conn,1,3,1

RESPONSE.WRITE "<ul class='list-group'>"
FOR I=1 TO AIR.RECORDCOUNT
RESPONSE.WRITE "<li class='list-group-item'><a href='javascript:void(0);'><span class='bold'></span>" + AIR.FIELDS("AIRPORT") + "-" + AIR.FIELDS("AIRPORT_NAME") + " [" + AIR.FIELDS("AIRPORT_CODE")+ "]" +  "</a></li>"
AIR.MOVENEXT
NEXT
RESPONSE.WRITE "</ul>"
%>

All i get is "retuned" and nothing after that. I check in firebug. Also I change the 'type':'GET' & request.form("locKeyword"), but nothing return. IF I directly hit this url (AIR_NAME_SEARCH_2.ASP?locKeyword=k) on browser i will return file. What would i be doing incorrect?

Daniel Smith
  • 1,626
  • 3
  • 29
  • 59
  • you need to mention the data type in your ajax. Ex : datatype : json – DinoMyte Nov 09 '15 at 20:21
  • what is this `msg` in `$(".ajax_response").fadeIn("slow").html(msg);` It probably should be `responseText`? – Victor Levin Nov 09 '15 at 20:23
  • oops! you are right. Its $(".ajax_response").fadeIn("slow").html(responseText); – Daniel Smith Nov 09 '15 at 20:33
  • @SandipKr So does it work now? – Victor Levin Nov 09 '15 at 20:34
  • @Zealander, No Its not work. Nothing reply form ajax. You want to see the live url? – Daniel Smith Nov 09 '15 at 20:37
  • Sure, post your url. – Victor Levin Nov 09 '15 at 20:39
  • Check in first textbox: http://qubedns.co.in/codes/design/rnp/flight-search.html – Daniel Smith Nov 09 '15 at 20:42
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/94644/discussion-between-sandip-kr-and-zealander). – Daniel Smith Nov 09 '15 at 20:46
  • @SandipKr, you have CORS issue. See the error in the console `http://103.231.43.134/NewRetailer/AIR_NAME_SEARCH_2.ASP?locKeyword=a. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://qubedns.co.in' is therefore not allowed access.` Your server at `103.231.43.134` needs to allow cross-origin calls. To get you started: http://stackoverflow.com/questions/29748338/how-to-enable-cors-for-simple-ajax-web-application – Victor Levin Nov 09 '15 at 20:47
  • So how to I enable this? thanks – Daniel Smith Nov 09 '15 at 20:58
  • Depends on your server. You basically need to add HTTP headers to allow Cross-Origin. Search for "CORS + type of your server" i.e. "Enable CORS IIS7" Or ask this as a separate question. – Victor Levin Nov 09 '15 at 21:04
  • I have search for above issue over internet, I am confusing on adding header in web.config. Can you send me the exact code to accept GET & POST method @ Zealander – Daniel Smith Nov 10 '15 at 07:58

0 Answers0