here is my code
<script>
$('#btnLogin').click(function () {
var body = {'grant_type': 'password','Email':$('#Email').val(),'password': $('#Password').val()};
alert(JSON.stringify(body));
$.ajax({
url: 'http://localhost:46382/Token',
method: 'POST',
ContentType: 'application/x-www-form-urlencoded',
data: body,
success: function (d) {
console.log(d);
alert("Login successfully Successfully");
sessionStorage.setItem("accessToken", response.access_token);
window.location.href = 'home';
},
error: function (error) {
alert("Error ");
}
});
});
</script>
and rest all the configuration in web api is default
What I have tried:
I have also tried changing the content type to application/json
and I have added
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
<add name="Access-Control-Allow-Methods" value="GET,POST,PUT,DELETE,OPTIONS" />
<add name="Access-Control-Allow-Credentials" value="true" />
in web config
And it is working when posting from code behind,
but I want do this by json