【问题标题】:Send data to another JavaScript file from a JavaScript file从 JavaScript 文件向另一个 JavaScript 文件发送数据
【发布时间】:2017-12-28 00:15:42
【问题描述】:

当管理员进入面板时,我想在面板中看到该管理员的信息。但是系统上有不止一个管理员。因此,我需要根据登录页面输入的邮件,找到登录系统的管理员。当我单击提交按钮时,我需要将此邮件从 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

【问题讨论】:

  • 您使用的是 ASP.NET 吗?您能否提供有关您正在使用的技术的更多信息?

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


【解决方案1】:

如果您使用的是 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
}

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-16
    • 2013-08-02
    • 1970-01-01
    • 2023-03-08
    • 2013-06-22
    • 1970-01-01
    相关资源
    最近更新 更多