G
G
Gagatyn2018-04-21 23:11:16
JavaScript
Gagatyn, 2018-04-21 23:11:16

How to get jsonp data?

Hello!
The server supports jsonp request. I use this code:

var URL; // сама ссылка на json файл.
 var xhr = new XMLHttpRequest();

 xhr.responseType = 'json';

 xhr.addEventListener('load', function(evt) {
   if (xhr.status === 200) {
     console.log(xhr.response);
   } else {
     console.error(xhr.status);
   }
 });
  xhr.open('GET', URL);
  xhr.send();

Received a file in the Network tab in Chrome, the file says:
/**/ typeof callbackName === 'function' && callbackName([{"name":"Name",...}])
(... -- t .e. a lot of data)
How can I use (display) this data, how to transfer it, I can’t understand, I can’t get it xhr.response writes null in the console . If not for this line, I would have easily received arrays of objects. In addition, please give links where work with jsonp is described, please.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question