如何重复查询?

How do I repeat a query?

我需要重复以下查询以增加 google 个图像的结果。单击按钮后执行代码。

Google 文档说:

Google Custom Search and Google Site Search return up to 10 results per query. If you want to display more than 10 results to the user, you can issue multiple requests (using the start=0, start=11 ... parameters) and display the results on a single page. In this case, Google will consider each request as a separate query, and if you are using Google Site Search, each query will count towards your limit.

Other SO question says

To get more result you should make multiple calls. in each different call, increase the value of parameter 'start' by 10.

还有this one says:

Now you can not ask google for more than 10 results at a time. So you have to query again asking for 10 result starting from 11. So In next query, keep num=10 and start=11. Now you can get all the results by changing start value.

如何重复以下并每次增加start参数?

    function googleImages() {
        var myCx = "MY_CX";
        var myKey = "MY_KEY";
        $.getJSON("https://www.googleapis.com/customsearch/v1", {
            q: termS + " in 1930 in " + country,
            alt: "json",
            searchType: "image",
            cx: myCx,
            num: 10,
            start: 0,
            key: myKey,
            rights: "cc_publicdomain",
            filter: "1",
            safe: "high",
            imgType: "photo",
            fileType: "jpg"
        },
        function (data) {
            $.each(data.items, function(i,item) {    
                $(".my_images .row .grid").append('<div class="col-sm-4 grid-item"><div class="thumbnail"><img class="img-responsive" src="' + item.link + '"></div></div>');
            });
            var $grid = $('.grid').packery({
            // options
            itemSelector: '.grid-item',
            percentPosition: true
        });
        $grid.imagesLoaded().progress( function() {
            $grid.packery('layout');
        });
        });
    }

您应该在调用之间保存 start 值,例如您可以使用这样的模式:

   function createGoogleImagesLoader(initialValue) {
       var _start = initialValue || 0;
       var imagesCount = 10;

       return function() {
            $.getJSON("https://www.googleapis.com/customsearch/v1", {
                ...
                num: imagesCount,
                start: _start
             },..);
            _start += imagesCount;

       }
    }

var googleImages = createGoogleImagesLoader();
googleImages() // load from 0 to 10
googleImages() // load from 10 to 20 etc.