Reputation: 33
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
Reputation: 71
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