Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only Firefox TypeError: "NetworkError when attempting to fetch resource."

I have a page which loads content dynamically, and I make several calls to backends API's all these calls have the same configuration, like this:

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
  });   

When the page load, call many functions like this:

get_data_1(); get_data_2(); ...

All the responses of the backend API have the same output format (JSON) and have the same headers, I'm using an only server (localhost), but only some calls get the error and others work fine, the problem is only with Firefox with chrome, opera, and edge I no have any error.

like image 395
Juan Carlos Avatar asked Jun 25 '20 15:06

Juan Carlos


People also ask

What does networkerror mean in Firefox?

Error: Network Error when attempting to fetch resource. Error: NetworkError when attempting to fetch resource. For bugs in Firefox Desktop, the Mozilla Foundation's web browser. For Firefox user interface issues in menus, bookmarks, location bar, and preferences. Many Firefox bugs will either be filed here or in the Core product.

How to know when to use TypeError when network error occurs?

Sometimes when you deal with Network problems, you need to know when having a network error. A fetch () promise will reject with a TypeError when a network error is encountered, although this usually means permission issues or similar

Why does a fetch() promise reject with a TypeError?

A fetch () promise will reject with a TypeError when a network error is encountered, although this usually means permission issues or similar But it isn’t good enough, because sometimes you have a TypeError inside above ` doSomething ` function, then this will make your app misunderstand the real problem.

How to debug a network request in Firefox?

You can use the Network tab in Firefox's web console to debug the request and response. Sorry, something went wrong. .. Sorry, something went wrong. Have you check errors like CORS?


1 Answers

I found the reason why some request has not a response, is a bug with the ad blocker that I have installed in Firefox when I disable the ad blocker, all works fine

like image 181
Juan Carlos Avatar answered Oct 18 '22 12:10

Juan Carlos