Ajax转到网址页面[重复]

This question already has answers here:
                </div>
            </div>
                    <div class="grid--cell mb0 mt4">
                        <a href="/questions/38089507/how-to-change-url-after-success-in-ajax-without-page-reload" dir="ltr">How to change url after success in ajax without page reload</a>
                            <span class="question-originals-answer-count">
                                (3 answers)
                            </span>
                    </div>
            <div class="grid--cell mb0 mt8">Closed <span title="2017-01-13 19:08:16Z" class="relativetime">3 years ago</span>.</div>
        </div>
    </aside>

I have an ajax call like so:

$("#Navbar-Search-Button").click(function (e) {
    SendToController();
    return false;
});

function SendToController() {
    var regNumber = $("#IDValue").val().trim();
    $.ajax({
        url: '/ControllerName/ActionName',
        data: { 'argument': regNumber },
        type: 'GET',
        cache: false,
        success:function(data) {
            $("body").html(data);
            $(".dropdown-toggle").dropdown();
            document.location = url.val();   // tried this doesn't work
        },
        error: function () {
            $("#Dialog").dialog('open');   
        }
    });
}

Now I know ajax updates without a page refresh, but on success I would like the page to be the url parameter, and not the page that I called the ajax function on

Any help is appreciated.

</div>

Current, it looks like you are making an AJAX request and then immediately reloading the page, which will cause your newly loaded content to disappear, which is worth noting. If you don't want this to occur, simply just update the content and don't navigate away.

Regarding Navigating

Set the window.location.href attribute to handle this within your success block :

success:function(data) {
        $("body").html(data);
        $(".dropdown-toggle").dropdown();
        // This will navigate to your preferred location
        window.location.href = url;   
},

Updating the URL without Navigating

If you wanted to update the content within the URL without actually navigating away, you could consider using an approach that relied on updating the history as opposed to navigating away using something like this via the history.pushState() function :

success:function(data) {
        $("body").html(data);
        $(".dropdown-toggle").dropdown();
        // This will navigate to your preferred location
        history.pushState({},"Your Title,url);
},

Regarding Using an MVC URL Directly

At present, you currently have your URL hard-coded to a given location, which can work in some scenarios, however it can make your code frail if any changes occur.

A recommendation would be to store the proper URL (resolved from MVC) in a data attribute and then use it when performing your navigation as seen below :

<!-- HTML -->
<input id="Navbar-Search-Button" type="submit" class="btn btn-default" value="Search" data-url="@Url.Action("Action","Controller")" />

<!-- Javascript -->
$("#Navbar-Search-Button").click(function (e) {
    // Resolve your URL here
    let url = $(this).data('url');
    SendToController(url);
    return false;
});

function SendToController(url) {
    var regNumber = $("#IDValue").val().trim();
    $.ajax({
        url: url,
        data: { 'argument': regNumber },
        type: 'GET',
        cache: false,
        success:function(data) {
            $("body").html(data);
            $(".dropdown-toggle").dropdown();
            document.location = url;
        },
        error: function () {
            $("#Dialog").dialog('open');   
        }
    });
}