0 javascript jquery json jsonresult asp.net-mvc-4
I'm trying to catch data from the AJAX POST, which I've sent via jQuery to controller endpoint of ASP.NET MVC, like this:
$("form#auth").submit(function() {
var login = $('input[id=login]').val();
var password = $('input[id=password]').val();
$.ajax({
url: "/Home/Auth",
type: "POST",
data: "Login=" + login + "&Password=" + password,
dataType: 'json',
contentType: 'application/json; charset=utf-8'
success: function() {
}
});
Run Code Online (Sandbox Code Playgroud)
I've tested the controller understads what I'm sending to him, but the main problem is with the returning the result for my jQuery function.
I'm returning the result from Controller like this: http://ideone.com/hNkF3Z
But I don't understand why the server is returning a file for download:

If to open the file, the result is valid: {"Result":"failed"}
I know, that I didn't write a code in a success function in JS, but I think server must not return a file download and also the debugger must stop at the breakpoint, which was defined on last scope } of success function.
您所看到的是默认表单提交.因为您不会阻止默认的浏览器操作,所以仍然会发布表单,就好像事件处理程序甚至不存在一样.
更新您的JavaScript以防止默认的浏览器行为 e.preventDefault()
$("form#auth").submit(function(e) {
e.preventDefault();
/* rest of your code here. */
}
Run Code Online (Sandbox Code Playgroud)