Skip to content

Instantly share code, notes, and snippets.

@sanmai
Last active October 30, 2018 01:09
Show Gist options
  • Save sanmai/a2431ce9d8dfd54920c90d6dddaf3f62 to your computer and use it in GitHub Desktop.
Save sanmai/a2431ce9d8dfd54920c90d6dddaf3f62 to your computer and use it in GitHub Desktop.
jQuery.ajax({
dataType: "json",
// https://www.postindexapi.ru/json/199/199151.json
url: 'https://www.postindexapi.ru/json/'+postcode.substring(0, 3)+'/'+postcode+'.json',
beforeSend: function() { // Уведомим пользователя, что загрузка идёт
$("td:last-child p.description.notice, td:last-child p.description.alert", postcode_field.parents("tr")).remove();
$('<p class="description notice loading"></p>').text("Загрузка…").appendTo($("td:last-child", postcode_field.parents("tr")))
},
success: function(data){
postcode_field.val(data.Index);
region_field.val(data.Region);
area_field.val(data.Area);
city_field.val(data.City);
if (data.Index != postcode) {
var message = "Вы ввели устаревший почтовый индекс: "+postcode+", ваш текущий индекс: "+data.Index;
$('<p class="description notice"></p>').text(message).appendTo($("td:last-child", postcode_field.parents("tr")))
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment