javascript - How to use YQL to retrieve web results? -
I have difficulty setting a simple HTML file using Javascript to display the results of the YQL query.
I understand how to set selection statements in the YQL console (example: search title, abstract, url, search.web where query = "pizza"). But I do not know how it can be displayed on the html file?
Can anyone explain how to display the results of that statement? The code snippet will be appreciated!
BTW, I've read YQL docs but they are a bit complicated.
The only way to get YQL results through client-side JavaScript is JSON-P (or additional proxy ) Is a cover for this YQL service:
function YQLQuery (query, callback) {this.query = query; This.callback = Callback || Function () {}; This.fetch = function (if (! This.query ||! This.callback) {new error ('YQLQuery.fetch (): parameters can be undefined');} Var scriptEl = document.createElement ('script '), UID =' Wyk '+ new date (), EncodedConnecti = encodercompany (this. Some.); Example = this; YQLQuery [uid] = function (jsn) {instance.callback (json); YQLQuery [uid] Delete; document.body.removeChild (scriptEl);}} ScriptEl.src = 'http://query.yahooapis.com/v1/public/yql?q=' + Encoded '+ & amp; Format = Jason & amp; Callback = YQLQuery. '+ UID; document.body.appendChild (scriptEl);};}
Usage: < / Strong>
// Prepare your query: var query = "Select from RSS * where url = 'somefeed .com' border1 '; // Define your callback: var callback = Function (data) {var post = data.query.results.item; alert (post.title);}; // with query immediately: var firstFeedItem = new YQLQuery (query, callback); // if you are ready Then go: firstFeedItem.fetch (); // go!!
More info :
Comments
Post a Comment