IE incompatability with [removed].href

后端 未结 3 1714
隐瞒了意图╮
隐瞒了意图╮ 2020-12-07 03:20

I\'m using a callback from an AJAX post request to navigate to a new page, but it is not working on Internet Explorer. My code is as follows:

$.ajax({ 
    t         


        
相关标签:
3条回答
  • 2020-12-07 03:46

    It's the parentheses. href is not a function, so trying to invoke it—window.location.href("/step2.php")—is a TypeError.

    Assign to href like you do on the next line, or better, use location.assign():

    location.assign('/step2.php');
    

    While you can directly assign to location's properties (location.href='...';) to cause the browser to navigate, I recommend against this.

    Internally, doing so is just calling location.assign() anyway, and assigning to properties does not always behave the same in all browsers.


    Regarding, async:false, never do that. If you make a synchronous XHR request, you're doing it wrong. 8.4% of reported IE9 hangs were due to synchronous XHR blocking the browser.

    Given that you have it in a callback, the assignment to location won't happen until the POST completes, so I'm not sure what you mean by "the page would change before the POST completes." (Did you forget to cancel a form's submit?)

    0 讨论(0)
  • 2020-12-07 03:46

    IE only like full url.

    var fullURL = 'http://www.your_site.com/step2.php';
    
    $.ajax({ 
        type: "POST",
        url: phpUrl,  
        data: data,  
        async: false, 
        success: function() {
    
            window.location.href(fullURL);
    
        },  
        dataType:'json'         
    }); 
    
    0 讨论(0)
  • 2020-12-07 04:03

    window.location.href = "/step2.php" is just fine.

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