Why does my jQuery/YQL call not return anything?
- by tastyapple
I'm trying to access YQL with jQuery but am not getting a response:
http://jsfiddle.net/tastyapple/grMb3/
Anyone know why?
$(function(){
$.extend(
{
_prepareYQLQuery: function (query, params) {
$.each(
params, function (key) {
var name = "#{" + key + "}";
var value = $.trim(this);
if (!value.match(/^[0-9]+$/)) {
value = '"' + value + '"';
}
query = query.replace(name, value);
}
);
return query;
},
yql: function (query) {
var $self = this;
var successCallback = null;
var errorCallback = null;
if (typeof arguments[1] == 'object') {
query = $self._prepareYQLQuery(query, arguments[1]);
successCallback = arguments[2];
errorCallback = arguments[3];
} else if (typeof arguments[1] == 'function') {
successCallback = arguments[1];
errorCallback = arguments[2];
}
var doAsynchronously = successCallback != null;
var yqlJson = {
url: "http://query.yahooapis.com/v1/public/yql",
dataType: "jsonp",
success: successCallback,
async: doAsynchronously,
data: {
q: query,
format: "json",
env: 'store://datatables.org/alltableswithkeys',
callback: "?"
}
}
if (errorCallback) {
yqlJson.error = errorCallback;
}
$.ajax(yqlJson);
return $self.toReturn;
}
}
);
$.yql(
"SELECT * FROM github.repo WHERE id='#{username}' AND repo='#{repository}'",
{
username: "jquery",
repository: "jquery"
},
function (data) {
if (data.results.repository["open-issues"].content > 0) {
alert("Hey dude, you should check out your new issues!");
}
}
);
});