2015-04-30 12 views
0

我的jQuery的的onclick,充分利用操作方法響應到jQuery的

$(document).ready(function() { 
    $("#submitSave").on("click", function() { 
     var confirmPassword = $("#txtLgnPasswordConfirmReset").val(); 
     var passwordReset = { 
      UserName: $("#txtLgnUsername").val(), 
      Password: $("#hdnOldPassword").val(), 
      NewPassword: $("#txtLgnPasswordReset").val() 
     } 
     $.ajax({ 
       type: "POST", 
       url: "/Account/PasswordReset", 
       data: passwordReset      
      }); 
     }); 
    }); 

下面是由上述的jQuery呼籲「點擊」我的控制器的操作方法,

[HttpPost] 
public ActionResult PasswordReset(User user) 
{ 
    if (_lfAPI.PasswordReset(user)) 
    { 
     return RedirectToRoute(Constants.Login); 
    } 
    return View(); 
} 

如果我的,如果上述方法中的(條件)返回true,我想顯示通知消息... 我的通知消息,

​​

在此先感謝...

+1

'返回新HttpStatusCodeResult(HttpStatusCode.OK)'一個好結果,'返回新HttpStatusCodeResult(HttpStatusCode.Unauthorized);'對於失敗的結果。然後你可以掛鉤到'$ .ajax()。done()'&'.fail()' – CodingIntrigue

回答

2

您可以在阿賈克斯成功回調處理這個作爲

$.ajax({ 
 
    type: "POST", 
 
    url: "/Account/PasswordReset", 
 
    data: passwordReset, 
 
    success: function(data) { 
 
    if (data == true) { 
 
     //show success msg 
 
    } 
 
    } 
 

 
});

+0

是的,你可以使用這個如果你只有布爾返回從你的服務 – syms

+0

試試這個 var data ='false'; (data == true)alert('here1'); if(data =='true')alert('here2'); if(data)alert('here3') 你會得到一個想法 – syms

+0

有趣的事情與'「假」== true「(和'」假「==假'也返回'假',順便說一句)謝謝。這是使用弱類型語言時發生的情況。 – Regent

0

使用成功回調在你的Ajax調用。

$.ajax({ 
    type: "POST", 
    url: "/Account/PasswordReset", 
    data: passwordReset , 
    success: function (resp) { 
     if (resp == "true") { 
      // do your stuff here 
      notifyMessage.showNotifyMessage('info', 'Your password has been reset.Please login with your new password.', false) 
     } 
    },     
}); 
});