开发者

jquery json google ws api

hello i am trying to get the google json from my local host http://code.google.com/apis/imagesearch/v1/jsondevguide.html?#basic_query

and i getting: Line: 4984 Error: Access is denied. from the jquery what is missing??

well this is the code

<script type="text/javascript" charset="utf-8">
    $(document).ready(function () {

        var _url = 'https://ajax.googleapis.com/ajax/service开发者_开发知识库s/search/images?v=1.0&q=fuzzy%20monkey';
        _url = 'http://code.google.com/ajax/services/search/images?v=1.0&q=fuzzy%20monkey';
        var _serverParam = "";

        var aa = $.getJSON(_url, _serverParam, theCallBack);
        //        alert(aa);
        //        function theCallBack(theData, theStatus) {
        //            alert(theData); alert(theStatus);
        //        }

    });
    function theCallBack(theData, theStatus) {
        alert(theData); alert(theStatus);
    }
</script>


Yes, the second url seems to be broken - it returns a 404 error. However you need to add '&callback=?' to the end of the URL in order not to get a XMLHttpRequest error (Origin http://... is not allowed by Access-Control-Allow-Origin).

Here's the code that works:

$(document).ready(function () {
    var _url = 'https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=fuzzy%20monkey&callback=?';
    //_url = 'http://code.google.com/ajax/services/search/images?v=1.0&q=fuzzy%20monkey&callback=?';

    $.getJSON(_url, function (data) {
        alert(data);
    });
});


var _url = 'https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=fuzzy%20monkey';
_url = 'http://code.google.com/ajax/services/search/images?v=1.0&q=fuzzy%20monkey'; 

I think you are setting _url twice, then calling _url = 'http://code.google.com/ajax/services/search/images?v=1.0&q=fuzzy%20monkey';

which fails: http://code.google.com/ajax/services/search/images?v=1.0&q=fuzzy%20monkey

if you set the second _url to something else and call the first established _url youl find it works. https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=fuzzy%20monkey - retreives a image file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜