从JavaScript文件将数据发送到另一个JavaScript文件

时间:2017-12-27 06:52:16

标签: javascript c# html ajax model-view-controller

我想在管理员进入面板时在面板中看到此管理员的信息。但是系统上有多个管理员。因此,我需要找到根据登录页面输入的邮件登录系统的管理员。当我单击“提交”按钮时,我需要将此邮件从admin.js文件发送到landing_page.js文件。 如何将此数据从一个JavaScript文件发送到另一个JavaScript文件

使用MVC。我使用C#发送和接收数据。我为此使用了ajax。并使用“return false”禁用表单的页面刷新功能。

admin.cshtml

$("[name='login_form']").click(function () {
    $.post("/Home/AdminLogin", { email: $("#admin_email").val() }, function (data) {
        //// send the information of admin to _LayoutPage.cshtml
        var fl = data.xfirst_name;
        var ln = data.xlast_name;

        /*if password is correct*/
        if ($("#admin_password").val() == data.passwrd) {
            /*go to Users_Panel.cshtml*/
            window.location.href = "/home/dashboard";
            /**/
        }/**/
    })
    .fail(function (data) {
        alert("Server Error");
    });
});

我需要将'fl'和'ln'发送到landing-page.js

1 个答案:

答案 0 :(得分:0)

如果您使用的是ASP.NET(因为.cshtml),请查看本教程:https://www.aspsnippets.com/Articles/Simple-User-Login-Form-example-in-ASPNet.aspx

基本上,使用这样的登录表单:

<form id="form1" runat="server">
    <asp:Login ID = "Login1" runat = "server" OnAuthenticate= "ValidateUser"></asp:Login>
</form>

当用户单击“登录”时,您可以调用方法“ValidateUser”。此功能如下所示:

protected void ValidateUser(object sender, EventArgs e)
{
    [your logic to get user information goes here]

    FormsAuthentication.RedirectToLoginPage(); //Redirect to the page here
}

请提供有关您希望使用的技术的更多信息。

相关问题