Jquery ajax调用$ .each循环

时间:2018-01-26 19:46:39

标签: javascript jquery ajax get parameter-passing

我试图通过班级" doi"来检索保存在所有div中的网址。在data-value属性下使用.each()函数并将其传递给ajax调用,因此我可以从api中检索特定数据并将其作为字符串再次传递给特定的div。

现在我想我的问题是,这个指针不在ajax调用中工作。答案可能很简单,我想但我不知道怎么弄清楚。

jQuery(document).ready(function($) {
  $(".doi").each(function() {
    var doi = $(this).attr("data-value");
    $.ajax({
      headers: {
        Accept: "application/vnd.citationstyles.csl+json"
      },
      type: "GET",
      async: false,
      url: doi,
      success: function(data) {
        if (data) {
          $(this).text(JSON.stringify(data["is-referenced-by-count"]));
          //$(".doi").text(JSON.stringify(data["is-referenced-by-count"]));
        } else {
          $(this).text("no result...");
        }
      },
      error: function(jqXHR, textStatus, errorThrown) {
        $(this).text("error: " + textStatus);
      }
    });
  });
});

0 个答案:

没有答案