Ajax url does not change in asp.net mvc

时光总嘲笑我的痴心妄想 提交于 2019-12-24 08:55:46

问题


I have been trying to use ajax post to another actionresult.

However i have 3 problems about ajax.

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);?

My codes below,

Index ActionResult (Project starts from Index)

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

Index View

<body id="BodyPage">

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

</body>

JS Code:

<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 View:

<h1>Just for an example</h1>

My questions,

1-Why url does not change when i post data ?

2-Why i can not go previous and forwards page ?

3-Do i always have to refresh like $("#BodyPage").html(mydata)? Is there another easier way ?

Any help will be appreciated.

Thanks.

来源:https://stackoverflow.com/questions/21335361/ajax-url-does-not-change-in-asp-net-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!