首页 > 解决方案 > 获取简单 GET 请求的 NS_BINDING_ABORTED 错误

问题描述

为什么我会收到此错误?

这是我在 Firefox 中的“网络”选项卡的屏幕截图,显示了 NS_BINDING_ABORTED

我在这个线程中查看了NS_BINDING_ABORTED Shown in Firefox with HttpFox但我根本不知道它在说什么......

有人可以帮我吗?

谢谢

$(function() {
  let userName = null;
  let userStatus  = null;

  $("#search").on("click", function() {
    userName = $("#username").val();
    apiCall();
  });
  
  $(".dropdown-menu a").on("click", function() {
    $("button.dropdown-toggle").text($(this).text());
    userStatus = $("button.dropdown-toggle").text();
  });

  function apiCall() {
    if (userName !== null && userStatus !== null) {
      var api = `https://api.jikan.moe/v3/user/${userName}/animelist/${userStatus}`;
      fetch(api, {
        method: "GET",
        headers: {
          Accept: "application/json",
        },
      })
      .then(response => response.json())
      .then((data) => {
        console.log(data)
      })
      .catch((error) => {
        console.log(error);
      })
    }
  }
});

标签: javascripthtmljquerycss

解决方案


我在 $.get() ajax 调用中遇到了同样的问题。它位于从表单内的按钮触发的函数内。我将按钮移到表单标签之外,问题就消失了。


推荐阅读