-1
        function getval(data) {
        alert(data['url']);
    }



    $(document).ready(function () {
        var bingAPIUrl = "http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US&callback=getval";
        $.support.cors = true;
        var result = $.getJSON(bingAPIUrl, getval(data));

    });

I am trying to get the url property of get the image url from bing, can someone help me why the data result is undefined in my callback function 'getval'

Khaliq
  • 1

1 Answers1

0
getVal = function (data) {
    alert(data.query.results.json.images.url);
};
$.getJSON("https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20json%20where%20url%3D%22http%3A%2F%2Fwww.bing.com%2FHPImageArchive.aspx%3Fformat%3Djs%26idx%3D0%26n%3D1%26mkt%3Den-US%22&format=json&callback=", function(data) {
  getVal(data)
});
guest271314
  • 1
  • 15
  • 104
  • 177
  • I tried to make similar request directly to bing and still not able to pass data to callback function... – Khaliq Jul 19 '14 at 23:43
  • function getval(data) { alert(data.json.images.url); } $(document).ready(function () { var bingAPIUrl = "http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US&callback="; $.support.cors = true; $.getJSON(bingAPIUrl, '', function(data) { getval(data); }); }); – Khaliq Jul 19 '14 at 23:43
  • Tried original url as well, returned syntax error (unexpected `:`) although response appear to be valid json . Utilizing https://developer.yahoo.com/yql, should be able to fetch data with `data.query.results.json.images.url` within callback . Note, this should also be possible without jquery , utilizing `script` element with `jsonp` callback function name appended to url. Thanks – guest271314 Jul 20 '14 at 02:13