Answer the question
In order to leave comments, you need to log in
How to make a replacement when sending an ajax request?
Good afternoon!
I want to calculate the shipping cost using mail api.
The response from the server comes in the form:
{"rsp":{
"stat":"ok",
"locations":[
{"value":"city--abakan","name":"АБАКАН","type":"cities"},
{"value":"city--anadyr","name":"АНАДЫРЬ","type":"cities"},
... ,
{"value":"city--yaroslavl","name":"ЯРОСЛАВЛЬ","type":"cities"}
]}}
function (data) {
for (i = 0; i < data.rsp.locations.length; i++){
$("#from").append("<option>" + data.rsp.locations[i].name);
$("#to").append("<option>" + data.rsp.locations[i].name);
$.ajax({
url: "http://emspost.ru/api/rest/",
dataType : "jsonp",
data: ({
method:"ems.calculate",
from: $("#from option:selected").val(),
to: $("#to option:selected").val(),
weight: $("#weight").val()
}),
success:
function (data) {
if (data.rsp.stat == "fail"){
$("#raschet").empty().html("Ошибочный вес посылки");
$("#time").empty();
}
else {
$("#raschet").empty().html("Цена доставки: " + data.rsp.price);
$("#time").empty().html("время доставки: " + data.rsp.term.min + "-" + data.rsp.term.max + " дней");
}
Answer the question
In order to leave comments, you need to log in
Add the data-val attribute and write the city code in it, and the name in the option.
Like this
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question