You must send a request to api Yandex in js to receive and process data. Trying to write an ajax request:

$.ajax({ url: 'https://api-maps.yandex.ru/services/route/2.0/?callback=id_155276244170680561044&lang=ru_RU&token=e150d8d2f888f6936fee0e67ca1ca581&rll=40.186,58.808~45.10,30&rtm=atm&results=3', type: 'GET', success: function (data) { console.log(data); } }); 

Or

 var url = 'https://api-maps.yandex.ru/services/route/2.0/?callback=id_155276244170680561044&lang=ru_RU&token=e150d8d2f888f6936fee0e67ca1ca581&rll=40.186,58.808~45.10,30&rtm=atm&results=3'; var xhr = new XMLHttpRequest(); xhr.open('POST', url, false); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.send(data); 

But I just can not display data in the console (If you go to this address on the address bar, then everything is fine, the data is displayed. Maybe I’m generally digging in a different direction.

PS An error falls to the console:

  Access to XMLHttpRequest at 'https://api-maps.yandex.ru/services/route/2.0/?callback=id_155276244170680561044&lang=ru_RU&token=e150d8d2f888f6936fee0e67ca1ca581&rll=40.186,58.808~45.10,30&rtm=atm&results=3' from origin 'http://anew' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. 

PSS Or is it all solved on the side of the backend by parsing?

  • Access-Control-Allow-Origin: * there is no server in response ... - Stranger in the Q

1 answer 1

AJAX has restrictions on cross-domain queries (you can read if interested ). You cannot retrieve data with an AJAX request from Yandex. What you just write in the console. It is naturally easy to solve - write a PHP script in which there will be a request to the API and make an AJAX request to your PHP script. So you get the right data.

  • it's even easier just to remove the proxy for nginx - Stranger in the Q