简体   繁体   English

使用YQL进行跨域ajax请求

[英]Using YQL for crossdomain ajax request

I'm studying javascript and I'm trying to work with some json files. 我正在研究javascript,我正在尝试使用一些json文件。 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. 我是一个完全的初学者,我尝试了很多不同的方式,但现在我想从另一个使用YQL的服务器请求一个json文件,但我不明白如何。 For example if I have a json like : 例如,如果我有一个像json:

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

with YQL I transform it in: 使用YQL我将其转换为:

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. 我的想法是将json中的“卡片”保存在一个数组中,但我不明白该怎么做,因为我无法真正理解javascript中的回调是什么。

A JavaScript callback is simply a function. JavaScript回调只是一个函数。 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. URL中的回调参数应该传递一个函数名,服务器将返回一些JSON包含在对命名函数的调用中。

eg define a function myfunc : 例如定义一个函数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. 然后调用http://query.yahooapis.com/...callback=myfunc ,当返回响应时, myfunc将被执行并传递JSON对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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