使用字母表循环$ .getJSON

时间:2016-01-29 04:21:36

标签: javascript loops getjson

我正在使用SEARCHTERM循环$ .getJSON网址。

我想以编程方式将字母表中的每个字母添加到SEARCHTERM中,如下所示:

SEARCHTERM
SEARCHTERM
SEARCHTERM
SEARCHTERM a
SEARCHTERM a
SEARCHTERM a
a SEARCHTERM
a SEARCHTERM
a SEARCHTERM
SEARCHTERM b
SEARCHTERM b
SEARCHTERM b
b SEARCHTERM
b SEARCHTERM
b SEARCHTERM

这是我用来循环原始“SEARCHTERM”而不在每一端添加字母的代码。

以下是相关的javascript代码:

var suggestCallBack; // global var for autocomplete jsonp
var keywordCount = 0;
$('body').on("click", '#submit', function() {
  $('#keywords').html('');
  var search_input = $("#keyword").val();
  var language = $("#edit-domain").val();
  callAPI(search_input, language);
  return false;
});

function callAPI(s, language) {
  $.getJSON("http://suggestqueries.google.com/complete/search?callback=?", {
    "hl": language, // Language
    //"ds":"yt", // Restrict lookup to youtube
    "jsonp": "suggestCallBack", // jsonp callback function name
    "q": s, // query term
    "client": "youtube" // force youtube style response, i.e. jsonp
  });
  suggestCallBack = function(data) {
    var suggestions = [];
    var languageText = $("#edit-domain option:selected").text();
    $('#keywordTable').show();
    $.each(data[1], function(key, val) {
      suggestions.push({
        "value": val[0],
      });
      $('#keywordTable tr:last').after('<tr><td>' + s + '</td><td>' + val[0] + '</td><td>0</td><td>0</td><td>0</td></tr>');
      $('#keywordCount').text(++keywordCount);
      $('#keywordtext').text(s);
      $('#languageholder').text(languageText);
    });
  }
}

字母表代码(如果需要?)

var alphabet = "abcdefghijklmnopqrstuvwxyz0123456789".split("");
_.each(alphabet, function(letter) {
  callAPI(search_input + ' ' + letter);
});

总结:我希望相关代码也在开头和结尾添加字母表的每个字母,同时调用callAPI();

0 个答案:

没有答案