yqlQuery is a jQuery plugin that, by using Yahoo! Query Language, can allow you to bypass most normal boundaries imposed by cross-site scripting (XSS) rules and request a whole bunch of other data.
You can find an incredibly useful example of yqlQuery at 5dayoptions' website in the stock ticker. Howboutdat?
- Makes it possible to load other site's HTML through JavaScript. Easily.
- Lets you optionally request through authorized Yahoo! Developer Network keys and secrets (allows 20,000 API calls per hour as opposed to 2,000 with the public version).
- Possesses a framework that could make all sorts of categories of things to load possible.
- Unwaveringly forces massive crowds to idolize you.
Before doing anything, you must include jQuery and jquery.yqlquery.js (or the minified version, jquery.yqlquery.min.js) on your page like so
<script language="javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script> <script language="javascript" src="jquery.yqlquery.js" type="text/javascript"></script>Finally, that's over; we can move right on to the other stuff.
The structure of using yqlQuery goes like this:
$.yql( { format: "json", key: KEY, query: "select * from yahoo.finance.quotes where symbol in ('AAPL', 'GOOG', 'MSFT')", secret: SECRET, success: function(data) { console.debug(data); } } );NOTE: query is the only required property. That makes key, format (assumed "json"), and secret not so (neither is success but... wtf).
The previous code loads some stock information and logs it to the console. query is, of course, the query to run, success is the callback function, format is the type in which the data should be returned ("json", "text", "xml", ...), key and secret have to do with if you register an official application, and success is as mentioned before. The argument passed to the success function is the data which has been loaded. There's also a built-in function called getHTML which goes a little something like this:
$.yql( "getHTML" , { format: "text", success: function(data) { $("body").html(data); }, url: "http://www.google.com" } );Wuddyaknow? You just loaded Google's homepage into your body tag. Check out the repository for an example of this in action!
You can perfrom really fun requests in a snap with zero filler by doing something like this:
var a;$.yql({async: false,query:"select * from yahoo.finance.quotes where symbol in ('MSFT')",success:function(data){a=data;}})Bam. You just got the most recent stock information for Microsoft and stored it in a. How do you feel now?
if ( parseFloat(a.query.results.quote.LastTradePriceOnly) < 5 ) alert("OMG, buy some Microsoft stock. It's cheap as hell right now.");Fun, right?
- All that jQuery supports.
Public domain
yqlQuery is a project by Gabriel Nahmias, co-founder of Terrasoft.