简体   繁体   中英

Opening a new tab/window after an AJAX call

I need help making an ajax call and using the response to open a new tab; the code I have sort of works but if the function is called more than once, it will simply replace the contents of the first tab instead of opening another one.

function openInNewTab(url){
    let newTab = window.open("about:blank", "new_tab")
    $.ajax('api/path').done(function(response){
        newTab.location = url + '&data='+response;      
    })
}

How can I make it so a new tab will be opened each time the function is called?

Try this (url should be full qualified url, eg http://www.example.com/path/to/your/file/and/so/on )

function openInNewTab(url){
    $.ajax('api/path').done(function(response){
        window.open( url + '&data='+response, "_blank");    
    })
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM