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

145
Views
I am trying to post my json to the url. and I get error 405 but I can see request payload in chrome developer tools. what am I doing wrong
function addUser(username, email, callback) {
    var xhr = new XMLHttpRequest();
    var response;
    var success = !!Math.round(Math.random());
    console.log(success);
    if (!success) {
      response = JSON.stringify({
        success: success,
        error: "Oups, something went wrong!",
      });
    } else {
      response = JSON.stringify({
        success: success,
        user: {
          username: username,
          email: email,
        },
      });
    }
    console.log(response);
    xhr.open("POST", "/echo/json/", true);

    xhr.onload = function () {
      if (xhr.status === 200) {
        callback(JSON.parse(xhr.responseText));
      }
    };
    xhr.setRequestHeader(
      "Content-type",
      "application/x-www-form-urlencoded"
    );
    xhr.send("json=" + response);
  }

My function to call post method..I am trying to call this function with username and email as inputs which I will be getting from HTML form inputs.

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!