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

199
Views
form doesn't submit with java script

I wanna submit a form without refreshing

here is the code:

<form id="rout" >
    <div class="mb-3">
        <label for="exampleInputEmail1" class="form-label">your id</label>
        <input type="text" class="form-control" onchange="" id="exampleInputEmail1" aria-describedby="emailHelp">
    </div>
    <div class="mb-3">
       <label for="exampleInputPassword1" class="form-label">first name</label>
       <input type="text" class="form-control" id="exampleInputPassword1">
    </div>
    <div class="mb-3">
        <label for="exampleInputPassword111" class="form-label">last name </label>
        <input type="text" class="form-control" id="exampleInputPassword111">
    </div>
    <div class="d-grid gap-2">
        <button id="btbtbt" class="btn btn-primary" type="submit" style="text-decoration: none ">
            submit
        </button>
    </div>
</form>

<script>
    const myForm = document.getElementById("rout");
    myForm.addEventListener("submit", (e)=>{
      e.preventDefault();
      const req = new XMLHttpRequest();
      req.open("post","router.php");
      req.onload= function (){
        console.log(req.responseText);
      }
      req.send(new FormData(myForm));
    });
</script>

focus on the script part

here is what I got: enter image description here

I know this code works

I tested it before

but it's not working in here

What could be the reason?

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!