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

142
Views
location.href not redirecting to user page

I have a form which is is linked to signup.js which when someone presses the button start chatting it should redirect to user.php in my case it's not working

location.href = "user.php"; 

is giving the problem because i get success when i submit the form. But it doesn't work. It simply stays on the login page and nothing happens but gives sucess

const form = document.querySelector(".signup form"),
continueBtn = form.querySelector(".button input"),
errorText = form.querySelector(".txt-error");

form.onsubmit = (e) => {
    e.preventDefault();    //preventing from submitting
}

continueBtn.onclick = () =>{

   // AJAX code refernce w3schools
   let xhr = new XMLHttpRequest(); //object created
   xhr.open("POST", "php/signup.php", true);
   xhr.onload = () =>{
       if(xhr.readyState === XMLHttpRequest.DONE){
           if(xhr.status === 200){
               let data = xhr.response;
               if(data == "success"){
                    location.href = "user.php";
               }else{
                    errorText.textContent = data;
                    errorText.style.display = "block"; 
              }
           }
       }
    }
    // send form data to php through ajax
    let formData = new FormData(form);  //obj created
    xhr.send(formData); //sending data to php
}

These are my codes any help will be appreciated. What I am doing is that when the user clicks the submit button an ajax request is being executed to target php script which logs in the user and if user is logged in successfully then echoes back the message "login_successful" to the ajax request. By using if statement I check whether the message is "login_successful" else display the error.

If the message is "login_successful" the script redirects the user to the new page 'user.php' by using

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Your form variable is selected with .signup form, which will find the first <form> element within the first element with a signup class. For example:

<div class = "signup">
  <form>
    ...
  </form>
</div>

Presumably, you have a form with the class signup, so you want the selector form.signup

Once you select the correct element, your form.onsubmit listener should work.

The same goes for your continueBtn selector - right now it's selecting an <input> element inside another element with the class button. Presumably you want the selector input.button.

about 4 years ago · Juan Pablo Isaza Report
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!