Как я могу написать это заявление YQL для jquery jsonp - PullRequest
1 голос
/ 08 октября 2010

Я пытаюсь сделать некоторые междоменные вещи с YQL и Jquery, но у меня возникли небольшие проблемы с тем, чтобы этот запрос yql работал правильно.

Хорошо, так что это утверждение YQL, япытаясь заставить работать:

use 'http://yqlblog.net/samples/data.html.cssselect.xml' as data.html.cssselect; select * from data.html.cssselect where url="www.holylandmoments.org/devotionals/the-sabbath-experience" and css="#main-content p"

Теперь утверждение yql, которое я пытаюсь изменить, чтобы удовлетворить тому, что я пытаюсь сделать, это:

var yql = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent('select * from html where url="' + site + '"') + '&format=xml&callback=?';

Из того, что у меня естьпрочитайте, чтобы я мог выбирать и выбирать селекторы css. Мне нужно вызвать открытую таблицу данных.

Я не знаю, что или как я могу изменить в примере оператора yql, включив в него USE и ASв запрос.

Подойдет любая помощь.

Ответы [ 2 ]

1 голос
/ 09 мая 2012

см. Ниже пример того, как получать новости от YQL JSONP

http://www.techtricky.com/jquery-code-to-display-top-news-using-yql-jsonp-api-service/

1 голос
/ 12 октября 2010

Хорошо, я понял ... если кому-то еще нужно что-то подобное, посмотрите:

// Accepts a url and a callback function to run.

функция requestCrossDomain (сайт, обратный вызов) {

// Take the provided url, and add it to a YQL query. Make sure you encode it!
var yql = 'http://query.yahooapis.com/v1/public/yql?q=use' + "%20'http%3A%2F%2Fyqlblog.net%2Fsamples%2Fdata.html.cssselect.xml'%20as%20data.html.cssselect%3B%20" + encodeURIComponent('select * from data.html.cssselect where url="' + site + '"') + "%20and%20css%3D%22%23main-content%20p%22" + '&format=xml&callback=?';

// Request that YSQL string, and run a callback function.
// Pass a defined function to prevent cache-busting.
$.getJSON( yql, cbFunc );

function cbFunc(data) {
// If we have something to work with...
if ( data.results[0] ) {
    // Strip out all script tags, for security reasons.
    // BE VERY CAREFUL. This helps, but we should do more. 
    data = data.results[0].replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '');

    // If the user passed a callback, and it
    // is a function, call it, and send through the data var.
    if ( typeof callback === 'function') {
        callback(data);
    }
}
// Else, Maybe we requested a site that doesn't exist, and nothing returned.
else throw new Error('Nothing returned from getJSON.');
}
}
...