Change window location Jquery

后端 未结 6 1765
Happy的楠姐
Happy的楠姐 2021-01-01 14:37

I am using ajax to load my website content and want to update the window location when ajax is successful.

How can I update the window location to \"/newpage\"?? I n

相关标签:
6条回答
  • 2021-01-01 15:01

    If you want to use the back button, check this out. https://stackoverflow.com/questions/116446/what-is-the-best-back-button-jquery-plugin

    Use document.location.href to change the page location, place it in the function on a successful ajax run.

    0 讨论(0)
  • 2021-01-01 15:02

    You can set the value of document.location.href for this purpose. It points to the current URL. jQuery is not required to do this.

    0 讨论(0)
  • 2021-01-01 15:03

    I'm writing common function for change window

    this code can be used parallel in all type of project

    function changewindow(url,userdata){
        $.ajax({
            type: "POST",
            url: url,
            data: userdata,
            dataType: "html",
            success: function(html){                
                $("#bodycontent").html(html);
            },
            error: function(html){
                alert(html);
            }
        });
    }
    
    0 讨论(0)
  • 2021-01-01 15:07

    Assuming you want to change the url to another within the same domain, you can use this:

    history.pushState('data', '', 'http://www.yourcurrentdomain.com/new/path');
    
    0 讨论(0)
  • 2021-01-01 15:12

    I'm assuming you're using jquery to make the AJAX call so you can do this pretty easily by putting the redirect in the success like so:

        $.ajax({
           url: 'ajax_location.html',
           success: function(data) {
              //this is the redirect
              document.location.href='/newpage/';
           }
        });
    
    0 讨论(0)
  • 2021-01-01 15:13

    you can use the new push/pop state functions in the history manipulation API.

    0 讨论(0)
提交回复
热议问题