1

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.

5
  • Have a look at this codemag.com/Article/1301091 Commented Jan 24, 2014 at 14:47
  • Ther is also this library that can help you asual.com/jquery/address Commented Jan 24, 2014 at 14:50
  • thanks for help however i can not do this again i tried var pageName = $(this).attr("href"); window.history.pushState(null, "", pageName); Commented Jan 24, 2014 at 15:01
  • may anyone please help me ? Commented Jan 24, 2014 at 15:50
  • 1
    Google ajax deep linking and you will find how to do it Commented Jan 24, 2014 at 15:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.