title: Fetch failed loading: GET (with same path)
body: <p>Got an issue with fetch in js + Django</p>
  <pre><code>document.addEventListener(&quot;DOMContentLoaded&quot;, function () {
  // loading inbox as default
    load_mailbox(&quot;inbox&quot;);
    console.log(&quot;again loaded INBOX____________&quot;)
  // when form is submitted, send email to other user
    document.querySelector(&quot;#compose-form&quot;).onsubmit = function () {
      fetch(&quot;/emails&quot;, {
        method: &quot;POST&quot;,
        body: JSON.stringify({
          recipients: document.querySelector(&quot;#compose-recipients&quot;).value,
          subject: document.querySelector(&quot;#compose-subject&quot;).value,
          body: document.querySelector(&quot;#compose-body&quot;).value,
        }),
      })
        .then((response) =&gt; response.json())
        .then((result) =&gt; {
          // Print result
          console.log(result);
  // after sending email, loading page with sent emails
          load_mailbox(&quot;sent&quot;); 
        });
    };
  });
  </code></pre>
  <p>Load mailbox will call other function, which will fetch the data for the page</p>
  <pre><code>if (mailbox === &quot;sent&quot;) {
      fetch_mail_by_folder(&quot;sent&quot;)
    }
  </code></pre>
  <pre><code>
  function fetch_mail_by_folder(folder) {
    fetch(`/emails/${folder}`)
        .then((response) =&gt; response.json())
        .then((emails) =&gt; {
          emails.forEach(email =&gt; {
  // we fetching data for this page, and paste it into new div
            const element = document.createElement(&quot;div&quot;);
            element.innerHTML = `some data`;
            element.addEventListener(&quot;click&quot;, function () {
              get_email(email.id, folder);
            });
            const div = document.querySelector('#emails-view')
  // after that we add elements into existing html div
            div.append(element);
  
          })
          
        });
  }
  </code></pre>
  <p>There is an error when mail was sent, (after concole.log with &quot;email sent successfully&quot;)
  Fetch (fetch_mail_by_folder(&quot;sent&quot;)) was failed, (see screenshot).
  After, I tried to fetch the &quot;sent&quot; page with other function (just a simple button):</p>
  <pre><code>document
      .querySelector(&quot;#sent&quot;)
      .addEventListener(&quot;click&quot;, () =&gt; load_mailbox(&quot;sent&quot;));
  </code></pre>
  <p>And it works well (see screenshot) the same path was used and fetch was done successfully. Why first fetch failed, but the second one with the same path was successful? Any ideas what can be wrong with code?
  <a href="https://i.stack.imgur.com/toidM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/toidM.png" alt="error" /></a></p>