0

So I've been through an interesting learning experience. The end product produces this... No matter how hard I try I can not get the autocomplete to kick in .... I type in DELTA in the #air input field, it makes the request I get back a 200 on the response but then what? What am I missing here... Incidentally to me this looks like a simple Json response and not a JsonP response but for some reason when I send the request as Json I get a 401 error however just changing it to JsonP I get back the 200 responses.

Can someone help me comprehend why I can't get the dropdown to show the airline names (and record the selected airline code

Thanks...

[
  {
    "id": "DL",
    "label": "DELTA AIRLINES"
  },
  {
    "id": "GG",
    "label": "Delta Airlines (Group Space)"
  }
]

To get it I do this...

$(function() {

var url="http://<<ourinternalserver>>.com/scripts/broker.dll?_program=tas.json_airlines_test.sas";


$( "#air" ).autocomplete({
  source: function( request, response ) {
    $.ajax({
      url: url,
      dataType: "jsonp",
      data: {
        term: request.term
      },
      success: function( data ) {
            console.log('success');
      } // end of success
    }); // end of ajax
  },
  minLength: 2

 });
 });
Sridhar R
  • 20,190
  • 6
  • 38
  • 35
Richard C
  • 171
  • 12

1 Answers1

0

Try to add timeout parameter in $.ajax() like,

var req = $.ajax({
    url: url,
    dataType: "jsonp",
    data: {
      term: request.term
    },
    timeout : 10000
}); // end of ajax

req.success(function() {
    console.log('Success!');
});

req.error(function() {
    console.log('Error!');
});

Read jquery jsonp-requests and Autocomplete jsonp and jQuery ajax (jsonp) ignores a timeout and doesn't fire the error event

Community
  • 1
  • 1
Rohan Kumar
  • 40,431
  • 11
  • 76
  • 106