Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

223
Views
How do I make fetch from localhost not return 400 (Bad Request)?

I use to make a fetch request from localhost. The javascript for that was inside a script tag inside the index.html file:

<!DOCTYPE html>
<html lang="en">
    <head>
        ...
    </head>
    <body>
        ...
  
        <script type="text/javascript">
            ...
           var config = {}
           for (var file in guis) config[file] = guis[file].getValue()

           fetch('/one/two/three', {method: 'POST', body: JSON.stringify({type: type, config: config }) })
               .then(response => response.json())
               .then(function(test) {
                   if ('href' in test) {
                       setCookie("test_str", test['href'].split('http:',2)[1])
                       SomeFuction();
                       JumpTo();
                   } else {
                       var alert_message = `Can't run test. ${test.detail}`;
                       window.alert(alert_message);
                       JumpTo();
                   }
               })
               .catch(function (err) {
                   var alert_message = `Can't run test: ${err}`;
                   window.alert(alert_message);
               })
            ...
        </script>
    </body>
</html>

and it worked. But after a while I moved all the javascript (~800 lines), to an external file and I imported it like usually:

<script src="./index.js"></script>

and after that I started getting

POST http://172.17.0.2/one/two/three 400 (Bad Request)

How do I fix this error?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!