Is this valid JSON markup?

I am trying to get some information from a Russian delivery site. Being n00b for JSON / JQuery / Internets, I am stuck getting data in json format.

Following the company API, I go to the URL: http://emspost.ru/api/rest/?callback=json&method=ems.calculate&from=city--abakan&to=city--anadyr&weight=1

This returns:

json({"rsp":{"stat":"ok","price":"750","term":{"min":5,"max":9}}})

Following the jQuery docs, I tried:

<script>$.getJSON("http://emspost.ru/api/rest/?callback=json&method=ems.calculate&from=city--abakan&to=city--anadyr&weight=1",
        function(data){
        alert(data);
        });</script>

This returns null. Any idea what I'm doing wrong?

+3
source share
2 answers

Use callback=?, namely:

$.getJSON("http://emspost.ru/api/rest/?callback=?&method=ems.calculate&from=city--abakan&to=city--anadyr&weight=1",
function(data){
  alert(data);
});

:) JSONP , querystring ( , function json() {}, . ?callback=? jquery , success , $.getJSON() : ?callback=FunctioNameGiven, ' .

, , :

<script type="text/javascript">
  //returned javascript here, e.g. FunctioNameGiven({ object data });
</script>

, GET , JSONP , JSON :)

+5
+1

Source: https://habr.com/ru/post/1751905/


All Articles