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

210
Views
Javascript Post method in Razor Pages

I'm studying javascript methods but I have difficult to make POST method works. Below you can see the code that I use to test:

<form id="form_test">
    <h5>POST Method</h5>
    <input type="text" name="text" id="text_input">
    <button type="button" onclick="Save()">Send</button>
</form>
function Save() {
  var xhr = new XMLHttpRequest();
  var url = "/Page1?handler=Save";
  xhr.open("POST", url, true);

  let data = `{
        "Id": 78912,
        "Customer": "Jason Sweet",
        "Quantity": 1,
        "Price": 18.00
      }`;

  xhr.send(data);
}
public IActionResult OnPostSave()
        {
            return new JsonResult("my result");
        }

Any idea what can do wrong?

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

0

You need to fix the URL where you want to send the post request. Also need to use [HttpPost] attribute for the action method.

Below is link to an example which uses XMLHttpRequest to POST data to method

https://www.aspsnippets.com/Articles/Implement-AJAX-Call-using-XML-using-XmlHttpRequest-XHR-in-ASPNet-MVC.aspx

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!