JAVASCRIPT get location from Zip code using Ziptastic

JAVASCRIPT get location from Zip code using Ziptastic

I am working on shopping cart project on Laravel. The client wants to pre-populate the location detail like City, Country, State etc…

So let’s see How I can pre-populate and fetch location form Zipcode. We are using the┬áZiptastic API for fetching the location form zipcode.

Let’s see how we can fetch the location, first of all, we are creating the HTML like

      <input type="text" name="zipcode" id="zipcode">
      <input type="button" name="submit" value="Get Location" id="getLocation">
        <strong>Country : </strong><span id="country"></span><br/>
        <strong>County : </strong><span id="county"></span><br/>
        <strong>State : </strong><span id="state"></span><br/>
        <strong>City : </strong><span id="city"></span><br/>

Now, let’s create the JAVASCRIPT code for fetching the record from the Zipcode like

<script type="text/javascript">
              var zipcode = $("#zipcode").val();
              if( zipcode == "" ){
                alert("Please Enter Zipcode");
                url: "" + zipcode,
                cache: false,
                dataType: "json",
                type: "GET",
                success: function(result, success) {
                error: function(result, success) {




Now, you need to change the Country code from the API URL currently I set it to “US” for the testing purpose.

If you enter the US Zipcode 20036 then the output get something like

Country : US
County : District of Columbia
State : District of Columbia
City : Washington

The Ziptastic is the paid API you can find the more detail about Ziptastic from here.