I have this jQuery call:
jQuery.ajax({
type: "POST",
url: "http://localhost:5832/api/Login/Post",
data: JSON.stringify({ username: 'user12', password: '1234' }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert(data.d);
}
});
Which calls this web api controller action:
[System.Web.Http.AcceptVerbs("POST")]
[System.Web.Http.HttpPost]
public HttpResponseMessage Post(string username, string password)
{
string authenticationToken = "";
authenticationToken = hpl.LoginUser(username, password);
//Some other code
return Request.CreateResponse(HttpStatusCode.OK, authenticationToken);
}
I'm trying to submit the parameters with the data attribute but the call is not triggered.
When I'm changing the url to: http://localhost:5832/api/Login/Post?username=1&password=2
I'm able to reach the controller action.
How I can pass the parameters as part of the data attribute of the jquery call instead of query string params?
data: { username: "user12", password: "1234" },