JSFiddle - React, Tailwind, and code Playground
HTML
Точка прибытия: <select id="arrivalPoint"></select>
JavaScript
// This line taken from J50Npi.min.js (within this repo)
var J50Npi={currentScript:null,getJSON:function(b,d,h){var g=b+(b.indexOf("?")+1?"&":"?");var c=document.getElementsByTagName("head")[0];var a=document.createElement("script");var f=[];var e="";this.success=h;d.callback="J50Npi.success";for(e in d){f.push(e+"="+encodeURIComponent(d[e]))}g+=f.join("&");a.type="text/javascript";a.src=g;if(this.currentScript){c.removeChild(currentScript)}c.appendChild(a)},success:null};
var J50Npi2={currentScript:null,getJSON:function(b,d,h){var g=b+(b.indexOf("?")+1?"&":"?");var c=document.getElementsByTagName("head")[0];var a=document.createElement("script");var f=[];var e="";this.success=h;d.callback="J50Npi2.success";for(e in d){f.push(e+"="+encodeURIComponent(d[e]))}g+=f.join("&");a.type="text/javascript";a.src=g;if(this.currentScript){c.removeChild(currentScript)}c.appendChild(a)},success:null};
var url = 'http://emspost.ru/api/rest/?method=ems.get.locations&callback=arrivalPointRender';
var data = {plain: "true", type:"russia"};
// We need a function callback to be executed after the response is received
var arrivalPointRender = function(data){
var html = '', selected = false;
for(var i = 0; i < data.rsp.locations.length; i++){
if(data.rsp.locations[i].type=="cities") {data.rsp.locations[i].type="(город)"};
if(data.rsp.locations[i].type=="regions") {data.rsp.locations[i].type="(регион)"};
html += '<option value="'+data.rsp.locations[i].value+'"'+(selected?'':' selected')+'>'+data.rsp.locations[i].name+' '+data.rsp.locations[i].type +'</option>'
selected = false
}
document.getElementById('arrivalPoint').innerHTML = html;
}
J50Npi.getJSON(url, data, arrivalPointRender);
var urlCalcPost =...