POST 404 (Not Found) : jQuery.post() doesn't work but jQuery.ajax() works. Why?

Viewed 101

So I used to have a problem, I couldn't go for another page.

Now it is fixed, but I don't understand why it works now. I mean, they are pretty much similar.

Here's the code :

HomeController.cs

[HttpPost]
public JsonResult ValidStep1(Dictionary<string, List<string>> listUsers){
//some code
}

Index.cshtml BEFORE (DOESN'T WORK) + "POST http://localhost:55703/Home/ValidStep1 404 (Not Found)"

jQuery.post('/Home/ValidStep1', { listUsers: listUser }, function (data) {
  if (data) {
    document.location.replace("@ViewBag.nextStep");
  }
  else {
    document.location.replace("@ViewBag.errorStep");
  }
});

Index.cshtml NOW (IT WORKS)

jQuery.ajax({
  type: 'POST',
  url: '@Url.Action("ValidStep1", "Home")',
  data: { listUsers: listUser },
  success: function (data) {
      document.location.replace("@ViewBag.nextStep");
  },
  error: function () {
      document.location.replace("@ViewBag.errorStep");
  }
});

Do you have an idea ?

0 Answers
Related