Get remote JSON without jQuery?

What I want to do is get a thumbnail of a Vimeo image by capturing the json data returned by the request. I cannot use jquery because the javascript file is a small remote file that the user invokes, and jquery will increase its size many times.

I looked and everything seems to be talking about jquery or getting it in another language (e.g. php).

I found that I need to do this so far:

var script = document.createElement('script'); script.src = theUrlToMakeTheRequest; document.getElementsByTagName('head')[0].appendChild(script); 

I am not sure what I need to make a callback and not sure what I need to do in order to use the URL that is being added.

+6
source share
2 answers

From vimeo documentation

http://vimeo.com/api/docs/simple-api

It looks like you can put the callback = myfunction parameter at the end of the url to do a jsonp callback. So your code might look something like this.

 function myfunction(data) { alert(data); } var script = document.createElement('script'); script.src = theUrlToMakeTheRequest + '?callback=myfunction'; document.getElementsByTagName('head')[0].appendChild(script); 

On the download page there are examples of what you are trying to do. http://vimeo.com/api/docs/downloads

+7
source

You can do this with raw XMLHttpRequest,

Or for a small lightweight library that can do this, check out zepto.js

If you just enable zepto.js and ajax.js from ... https://github.com/madrobby/zepto/tree/master/src

You will have a jQuery-compatible solution in 30k uncompressed javascript (possibly <4k minified)

+3
source

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


All Articles