简体   繁体   中英

Using YQL for crossdomain ajax request

I'm studying javascript and I'm trying to work with some json files. I'm a complete beginner and I've tried in many different ways but now I would like to request a json file from another server using YQL but I don't understand how. For example if I have a json like :

http://m.airpim.com/json/public/search?q=daniele&k=&e=1

with YQL I transform it in:

http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20json%20where%20url%3D'http%3A%2F%2Fm.airpim.com%2Fjson%2Fpublic%2Fsearch%3Fq%3Ddaniele%26k%3D%26e%3D1'&format=json&callback=

But the problem is that I don't know what to put like callback. The idea was to save the "cards" from the json in an array but I don't understand how to do it because I can't really understand what are callbacks in javascript.

A JavaScript callback is simply a function. The callback parameter in the URL should be passed a function name, and the server will return some JSON wrapped inside a call to the named function.

eg define a function myfunc :

function myfunc(json){
    console.log(json);
    }

Then make a call to http://query.yahooapis.com/...callback=myfunc and when the response is returned, myfunc will be executed and passed the JSON object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM