javascript - Load Remote JSON File for Autocomplete Flexdatalist in Wordpress -


i have json file contains addresses, states , postcodes information. utilized autocomplete flexdatalist show suggestions while user types in address. works when json file local (data: 'myr-mini.json'), when use url starts "http:/.." doesn't work. kindly me on one. in advance.

<input id="cp_address" name='myr address' type='text' class='flexdatalist' placeholder='write country name' size="40"> <input id='postcode' name='postcode' type='text' placeholder='enter zipcode' size="40">  <script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery.min.js?ver=1.12.3'></script>     <script src="scripts/jquery.flexdatalist.js"></script> <script>      $('#cp_address').flexdatalist({      minlength: 2,      selectionrequired: true,      visibleproperties: ["value","state"],      searchcontain: true,      searchin: 'value',      searchdelay: 200,      noresultstext: 'no results found "{keyword}"',      data: 'https://studentsklm.com/wp-content/themes/classipress/myr-mini.json' }).on("select:flexdatalist",function(event, data){   $('#postcode').val(data.postcode); }); </script> 

it appears cors issue trying hit url json data. below sample using myjson.com has cors enabled, , typing in "per" country input brings results:

$('#cp_address').flexdatalist({    minlength: 2,    selectionrequired: true,    visibleproperties: ["value", "state"],    searchcontain: true,    searchin: 'value',    searchdelay: 200,    noresultstext: 'no results found "{keyword}"',    data: 'https://api.myjson.com/bins/v588t'  }).on("select:flexdatalist", function(event, data) {    $('#postcode').val(data.postcode);  });
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery.min.js?ver=1.12.3'></script>  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-flexdatalist/2.1.3/jquery.flexdatalist.min.js"></script>  <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-flexdatalist/2.1.3/jquery.flexdatalist.min.css" />    <input id="cp_address" name='myr address' type='text' class='flexdatalist' placeholder='write country name' size="40">  <input id='postcode' name='postcode' type='text' placeholder='enter zipcode' size="40">


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -