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

137
Views
How to distinguish between POST and PUT inside a form submit listener

Consider a form with a single button of type "submit":

<button type="submit" id="formSubmitButton">Submit</button>

When loading the page, I send a GET-request to my server, which will return an object that is used to fill out the form. If there is no object inside my server-side database, the form will be empty. I have attached an EventListener to my form, such that when the form is submitted, a POST request is send to my server. I only want to send a post request, however, when the form was initially empty (on loading the page). If it wasn't, I want to send a PUT request instead. And I don't want to introduce another button inside my form. Else, I assume, I could just send the POST/PUT requests upon clicking on either buttton. I just want the single button though.

Does anyone know of a nice way to accomplish this?

about 4 years ago · Santiago Trujillo
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!