JSFiddle - React, Tailwind, and code Playground

by stratdaz

HTML

<input type="text" class="city" placeHolder="city" style="width: 300px" />

JavaScript

$(function() {
        $( ".city" ).autocomplete({
            minLength: 3,
            source: function( request, response ) {
                $.ajax({
                    type: "GET",
                    url: "https://auspost.com.au/api/postage/country.json",
                    headers: { 'Authorization': '82d93f5d-6354-443c-95d2-5e31628097b0' },
                    dataType: "json",
                    data: {
                        excludePostPoxFlag: true,
                        q: request.term
                    },
                    success: function( data ) {
                        response( $.map( data.postalCodes, function( item ) {
                            return {
                                label: item.placeName + ", " + item.postalCode + ", " + item.adminCode1,
                                value: item.placeName + ", " + item.postalCode + ", " + item.adminCode1
                            }
                        }));
                    }
                });
            }
        });
    });