why jquery autocomplete doesnt work on https (secure pages)?

前端 未结 1 343
广开言路
广开言路 2021-01-14 21:13

I am trying to make jquery autocomplete to be work on https (secured pages) pages but its not showing any dropdown. I searched on this issue and found that its security issu

相关标签:
1条回答
  • 2021-01-14 22:01

    As I looked into the service provider they are supporting jsonp and the following sample worked

    $("input").autocomplete({
        source: function (request, response) {
            $.getJSON("http://ws.geonames.org/postalCodeSearchJSON?callback=?", 
              { 'postalcode_startsWith': request.term, maxRows: 12, style: "full" }, 
              function(data) {
                  if(data.postalCodes){
                      var x = $.map(data.postalCodes, function(v, i){
                          console.log(v)
                          return {
                              label: v.placeName + ' - ' + v.postalCode, 
                              v: v.postalCode
                          }
                      });
                      response(x);
                  }
              }
            );        
        }
    });
    

    Demo: Fiddle

    0 讨论(0)
提交回复
热议问题