weixin_33724046 2017-03-14 10:05 采纳率: 0%
浏览 28

jQuery POST重定向

I have written a program in ASP.NET MVC and i have an issue with my AJAX function.

If my function return success i want to redirect to another page , in POST Method. I cant use window.location so i have to make a form which will execute a post method.

Here is my code :

<body>
<div class="login">
    <div class="login-screen">
        <div class="app-title">
            <h1>bla bla bla</h1>
        </div>

        <div class="login-form">
            <div class="control-group">
                <input type="text" class="login-field" value="" placeholder="bla bla bla" id="login-name">
                <label class="login-field-icon fui-user" for="login-name"></label>
            </div>
            <div class="control-group">
                <input type="password" class="login-field" value="" placeholder="bla bla bla" id="login-pass">
                <label class="login-field-icon fui-lock" for="login-pass"></label>
            </div>

           <input type="button" class="btn btn-primary" id="button" value="bla bla bla"/>
        </div>
    </div>
    <div id="failedLogin">
    </div>

</div>
</body>

<script src="~/Scripts/Login.js"></script>

Here is m js code

$("#button").click(function () {
    $.ajax({
        url: "home/signIn",
        data: { userName: $("#login-name").val(), Password: $("#login-pass").val() },
        success: function (result) {
            if (result == "success") {

                var redirect = function (url, method) {
                    $('<form>', {
                        method: method,
                        action: url
                    }).submit();
                };

                redirect('/Account/Menu?Name=' + $("#login-name").val(), 'post');
            }
            else {
                var content = $("#failedLogin");
                var label = "<label class=\"result\">bla bla bla </label>";
                content.html(label);
            }
        }
    })

my c# code :

public string  signIn(string userName , string Password)
{
    var db = new OsemEntities();

    var name= from u in db.*********
                where u.UserName == userName & u.UserPassword == Password
                select u.UserName;

    if (name.Count() == 1)
        return "success";
    else
        return "fail";


}

My post redirect doesnt work , i will glad to get some help.

Thanks!

  • 写回答

2条回答 默认 最新

  • weixin_33690367 2017-03-14 10:26
    关注
      var redirect = function (url, method) {
                        $('<form>', {
                            type: method,
                            action: url
                        }).submit();
                    };
    

    Try This. method is depreciated. Use type instead

    评论

报告相同问题?

悬赏问题

  • ¥15 Coze智能助手搭建过程中的问题请教
  • ¥15 12864只亮屏 不显示汉字
  • ¥20 三极管1000倍放大电路
  • ¥15 vscode报错如何解决
  • ¥15 前端vue CryptoJS Aes CBC加密后端java解密
  • ¥15 python随机森林对两个excel表格读取,shap报错
  • ¥15 基于STM32心率血氧监测(OLED显示)相关代码运行成功后烧录成功OLED显示屏不显示的原因是什么
  • ¥100 X轴为分离变量(因子变量),如何控制X轴每个分类变量的长度。
  • ¥30 求给定范围的全体素数p的(p-2)/p的连乘积值
  • ¥15 VFP如何使用阿里TTS实现文字转语音?