K
K
keslo2014-05-04 18:19:51
JavaScript
keslo, 2014-05-04 18:19:51

How to get data from Yandex.Maps in JSON?

Good afternoon, ladies and gentlemen!

There is data on the link, for example - maps.yandex.ru/?text=%D0%BD%D0%BE%D1%82%D0%B0%D1%8...

How can I get this data into my script on js? Those. it is trite to assign a variable with which one could then work.

It is possible that not everything is so simple ...

I read that you can only get data from another domain in JSONP. But when requesting a view:

$.ajax({
    type: "GET",
    url: "url из примера см. выше (чтобы мета много не занимать)",
    dataType: "jsonp",
})

the error "Unexpected token :" is thrown .

As I understand it, the parser is trying to parse the data as JS code, which is why the error is thrown.

And I understand that most likely you need to use a callback function when receiving data via ajax in jsonp . But so far I don’t understand the meaning of this function: how to build and use it?

I will be grateful for your help!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Borisovich, 2014-05-05
@Alexufo

unexpected token. Looks like you have chrome. In Fox, he would have given you a more detailed parser error in the firebug.
Yes, the fact is that cross-domain request in jQuery only works if the dataType is specified as "jsonp" or "script". The work of the script tag is emulated where your request is substituted in src (like this) And before any callbacks, the response tries to be parsed as jsonp. And I couldn't do anything about it either. There are also pre filters and converters for jQuery.ajax but it didn't work out.
The easiest way is to make a proxy on your domain and work through it.
www.paulund.co.uk/make-cross-domain-ajax-calls-wit...
And it's strange that Yandex maps doesn't have a solution for developers that you have to fiddle with jsonp. You, apparently, missed something in the documentation of i.maps for developers.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question