Guarav
Guarav

Reputation: 33

How to use API to get Country,State,District

How to use API to get Country, State, District I am new to ajax so any one can help me thanks in advance

Ajax

 $(document).ready(function(){
    let api_url = 'http://www.postalpincode.in/api/pincode/';
    $('#pincode').on('focusout',function(){
        let pin = $(this).val();
        $.ajax({
          type:"POST",
          url:api_url+pin,
          // contentType:"application/json",
          dataType:'json',
          success:function(result){
            console.log(result);
          }
        });
    });
  })

pin:-334003

Upvotes: 0

Views: 491

Answers (1)

Khursand Kousar
Khursand Kousar

Reputation: 71

  1. You need to change your POST request to GET since it is a get request this gives error API Method Not Allowed when you use POST.
  2. you can get your values like this console.log(result); will show you complete response from API in your console and you can get your values like this

    console.log(result.PostOffice[0].Country);

Hope this helps

Upvotes: 1

Related Questions