0

I remember I read it somewhere that when submitting parameters values via ajax to API, there is an option so they don't show up in the URL. I've tried put them into data like:

$.ajax({
  type: "GET",
  url: "/api/myController/myLunch",
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  data: {"tableID":111, "firstCourse": "soup", ... },  // show up in header but not working
  header: {"tableID":111, "firstCourse": "soup", ... },  // neither
   success: function (data) { ... }
});

Controller get method:

[HttpGet]
[Route("myLunch")]
public IHttpActionResult myLunch(int tableID, string firstCourse, ...)
{ ... }

I kept getting 404 back. Basically I don't want to see like this:

/api/myController/myLunch?tableID=111&firstCourse=soup

I want to see only

/api/myController/myLunch
Jeb50
  • 3,784
  • 4
  • 26
  • 44
  • Please tag your question for better understanding. What language/framework, `jQuery` `C#`? and what you mean 'show up', I think in any case it won't show up in the address bar if you use `ajax` – Yu Jiaao Apr 12 '17 at 23:02
  • Have you try only use header and not provide the data parameter? and you want manually deal with the method arguments/parameters, maybe this link helps http://stackoverflow.com/questions/978061/http-get-with-request-body – Yu Jiaao Apr 14 '17 at 11:28

1 Answers1

0

You can hide parameters from the URL using the POST method. Actually, the main difference between the GET and POST methods is GET shows parameters in the URL while POST hides parameters from the URL. Meanwhile, you can use both to post data.