Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Return to View after ajax post to controller

$
0
0

Hi All,

I'm trying post data from View to controller and then return back to view. This is my script in view 

<script type="text/javascript">$(document).ready(function () { $("Submit").click(function (e) {
            e.preventDefault();

            var token = $('input[name=__RequestVerificationToken]').val();
            console.log(token);

            var dataToPost = $(this).serialize();$.ajax({
                url: "Process/Payment"
                , method: "POST"
                , data: {
                    __RequestVerificationToken: token
                    , page: dataToPost
                }
                , done: function (data) {window.location.replace (data.newUrl);
                    alert(data);
                }
                , error: function () {
                    alert("Ajax call failed");

                }
            })
        })
    })
</script>

and this is my controller. All data that wrap in 'Payment' model is in good shape. And, I want to return back to view (url: "Process/Payment")

        public ActionResult Payment(Payment payment) {
            return Json(new {
                                newUrl = Url.Action("Payment", "Process") //Payment as Action; Process as Controller
                            }
                        );
        }

but when the page return to localhost, I just get thisHow should I do to return the page that look like before hit submit button as POST ?

why "window.location.replace ()" can't redirect page to the original page ?

Thx's


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>