阿贾克斯网址不会在asp.net mvc的改变(Ajax url does not change i

2019-10-19 06:12发布

我一直在尝试使用Ajax后到另一个的ActionResult。

但是我对AJAX的3个问题。

1-Url does not change on browser.
2-I can not click to previous page and forward page on browser
3-Do i have to refresh html like  $("#BodyPage").html(mydata);?

我在下面的代码,

指数的ActionResult(项目从索引开始)

  public ActionResult Index()
    {
        return View();
    }

索引视图

<body id="BodyPage">

<input type="text" id="LoginEmailText"/>
<input type="text" id="LoginPasswordText"/>

</body>

JS代码:

<script>
    function LoginButton1OnClick() {
        $.ajax({
            type: "POST",
            url: "Login/MainPageRegister",
            cache:false,
            data:
                {
                    LoginEmailText: $("#LoginEmailText").val(),
                    LoginPasswordText: $("#LoginPasswordText").val(),
                },
            success: function (mydata) {
                $("#BodyPage").html(mydata);
            }
        });
    }
</script>

MainPageRegister的ActionResult:

    [HttpPost]
    public ActionResult MainPageRegister(MyModel model)
    {
        return View();
    }

MainPageRegister查看:

<h1>Just for an example</h1>

我的问题,

当我发布数据1 -为什么网址不会改变?

2,为什么我不能去以前和转发页面?

3,我总是要刷新像$( “#BodyPage”)。HTML(MYDATA)? 有另一种更简单的方法?

任何帮助将不胜感激。

谢谢。

文章来源: Ajax url does not change in asp.net mvc