drdarwin
drdarwin

Reputation: 107

loading google images with jQuery and json - NOT works in Opera

this code works fine in IE8, Chrome, Firefox, but in Opera 11.5 it works ONLY if I uncomment alert line, could anyone explain why?

$.ajax({
url:"https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=barack%20obama&key=YOUR-GOOGLE-API-KEY",
dataType:"jsonp",
success: function(data){


for (var i = 0; i < data.responseData.results.length; i++){

/* alert(data.responseData.results[i].tbUrl); */

 $('#image-container').append('<img src="' + data.responseData.results[i].tbUrl + '">' + '<br>');

}


}

});

here: http://jsonlint.com/ you can view a json response

Upvotes: 0

Views: 2113

Answers (1)

genesis
genesis

Reputation: 50982

You need to append callback=? to url to "allow" jsonp.

$.ajax({
    url: "https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=barack%20obama&callback=?",
    dataType: "jsonp",
    success: function(data) {


        for (var i = 0; i < data.responseData.results.length; i++) {

            /* alert(data.responseData.results[i].tbUrl); */

            $('#image-container').append('<img src="' + data.responseData.results[i].tbUrl + '">' + '<br>');

        }
    }


});

http://jsfiddle.net/genesis/TyDHK/2

Upvotes: 1

Related Questions