仅Firefox TypeError:“尝试获取资源时出现NetworkError。”

时间:2020-06-25 15:21:48

标签: javascript web firefox resources fetch

我有一个页面可以动态加载内容,并且我对后端API进行了多次调用,所有这些调用具有相同的配置,如下所示:

function get_data_1(){
  var data = {
    type: "home"    
  };
  
  fetch('../backend/get/slider.php',  {
      method: 'POST',      
      credentials: 'same-origin',
      body: JSON.stringify(data),
      headers:{
        'Content-Type': 'application/json'
      }
    })
    .then(function(response) {      
      return response.json();
    })
    .then(function(response) {            
      if( response.success ){
       //here proceses de code
      } else {               
       //here proceses de code if not success response
      }
    })
    .catch( function(error){      
      console.error(error);
      //Here is where the error catch and show the error: NetworkError when attempting to fetch resource
  });   

页面加载时,调用许多类似这样的函数:

get_data_1(); get_data_2(); ...

后端API的所有响应都具有相同的输出格式(JSON)和相同的标头,我使用的是唯一的服务器(localhost),但是只有某些调用会收到错误,而其他调用则可以正常工作,问题是仅在具有chrome,opera和edge的Firefox上,我没有任何错误。

1 个答案:

答案 0 :(得分:2)

我发现某些请求没有响应的原因,是我在禁用广告拦截器时在Firefox中安装的广告拦截器存在错误,一切正常