I'm working on a simple website that has a login/sign up feature. I just want to let the user get a message after he successfully sign in or sign up.
Here's my login method
Controller :
[HttpPost]
public ActionResult Login(string username,string password)
{
User loginTest = DB.Users.Where(a => a.User_Name.Equals(username) && a.User_Password.Equals(password)).FirstOrDefault();
if (loginTest != null)
{
//some code
}
else
{
return Redirect(Request.UrlReferrer.ToString());
}
}
I'm calling the login method like this
@using (Ajax.BeginForm("Login", "Home", new AjaxOptions() { UpdateTargetId = "logged-in", InsertionMode = InsertionMode.Replace }))
{
<input type="text" />
<input type="password" />
<input type="submit" value="login">
}
Here's my javascript function that I want to run if the logging in is successful.
<script type="text/javascript">
function JSalert(){
swal("Logged in successfully");
}
</script>
I already added
<link href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js"></script>
And I tested the function on button click and it's working, I'm just new to this and I wonder how to call this function after the user log in.
I checked these links already but I couldn't get any help.
Call a javascript function after ajax success
Run javascript function after Postback
Thanks.