$("#loginBtn").live('click', function () {
var username = $('#usernameField').val();
var password = $('#passwordField').val();
$.ajax({
type: 'POST',
url: '/Account/Login',
data: { username: username, password: password },
dataType: 'json',
async: true,
success: function (result) {
var asd = result;
},
error: function(e) {
var asd = e;
}
});
});
当我在Chrome控制台中键入e时,我得到了这个:
abort: function ( statusText ) {
always: function () {
complete: function () {
done: function () {
error: function () {
arguments: null
caller: null
length: 0
name: ""
prototype: Object
__proto__: function Empty() {}
<function scope>
fail: function () {
arguments: null
caller: null
length: 0
name: ""
prototype: Object
__proto__: function Empty() {}
<function scope>
getAllResponseHeaders: function () {
getResponseHeader: function ( key ) {
overrideMimeType: function ( type ) {
pipe: function ( /* fnDone, fnFail, fnProgress */ ) {
progress: function () {
promise: function ( obj ) {
readyState: 0
responseText: ""
setRequestHeader: function ( name, value ) {
state: function () {
status: 0
statusCode: function ( map ) {
arguments: null
caller: null
length: 1
name: ""
prototype: Object
__proto__: function Empty() {}
<function scope>
statusText: "error"
success: function () {
arguments: null
caller: null
length: 0
name: ""
prototype: Object
__proto__: function Empty() {}
<function scope>
then: function ( /* fnDone, fnFail, fnProgress */ ) {
__proto__: Object
有什么问题?错误消息对我说不多。我不会达到控制器方法,但它不会给我错误404它也找不到/帐户/登录。
答案 0 :(得分:0)
试试这个。
var DTO = { username: username, password: password };
现在将AJAX调用中的数据设置为
data: JSON.stringify(DTO),
当Controller方法具有以下签名时,这就是我们这样做的方式。
public JsonResult Login(string username, string password)
请勿忘记添加json3.js作为旧浏览器的后备广告。