0

以下のコードが機能しない理由がわかりません。私はjQuery 1.7.1を使用しています:

<script src="~/Scripts/jquery-1.7.1.min.js"></script>

私の_Layoutで。

が表示されますalert('hello');が、firebugを使用すると続きます:

RedirectToAction("MainIndex", "Home"); 

私はすべてが真実だと思います。

<script type="text/javascript">

$(document).ready(function () {

    $('#btn_submit').click(function () {
        alert('hello');

        $.ajax({

            url: 'Product/IsUserPeresent',
            cache: false,
            type: 'Get',
            success: function (result) {

                alert(result);
                @* var url = '@Url.Action("ncheckout", "Home")';
                $.post(url, {
                    name: result
                          });*@

            },
            error: function () {
                RedirectToAction("MainIndex", "Home");
           }
        });
    });
});

</script>

public ActionResult IsUserPeresent(){

    //var nam = User.Identity.Name;

    var nam = "alex";
    return Json(nam, JsonRequestBehavior.AllowGet);
}
4

1 に答える 1

1

これを試して:

$('#btn_submit').click(function (event) {
  event.preventDefault();

    alert('hello');

    $.ajax({

        url: 'Product/IsUserPeresent',
        cache: false,
        type: 'Get',
        success: function (result) {

            alert(result);
            @* var url = '@Url.Action("ncheckout", "Home")';
            $.post(url, {
                name: result
                      });*@

        },
        error: function () {
            window.location = '@Url.Action("MainIndex", "Home")';
       }
    });
});
于 2013-08-21T21:26:24.630 に答える