I try to call a ASP MVC action from outside of the domain via ajax.
Setup
I have hosted a MVC application with this action inside:
[HttpPost]
[AllowAnonymous]
public ActionResult AjaxLogin(LoginViewModel model)
{
[..Login stuff..]
return Json(new { Url: "...", Result: "..." });
}
Usage
For testing I try a manuell call with a HttpRequester addon from Firefox, with this result:
It is working correct and the answer is as expected. So now I want to made an ajax call from a second web page (different domain).
My jquery (2.2.0) ajax call looks like this:
var requestData = {
model: {
Email: emailValue,
Password: passwordValue
}
};
var requestPlain = JSON.stringify(requestData);
$.ajax({
url: json_login_url,
data: requestData,
method: 'POST',
async: false,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (result, textStatus, jqXHR) {
[...]
},
error: function (jqXHR, textStatus, errorThrown) {
[...]
},
beforeSend: function (jqXHR, settings) {
return true;
},
complete: function (jqXHR, textStatus) {
},
});
Problem
The ajax call only gives me an error.
SO why is my testcall working but my ajax call not?
Attempts
I also tried a network analysis with the firefox debugging tools.
But I don't understand why it is not working because it shows "status-code 200" but the result is empty!?