简体   繁体   English

在 AJAX 调用后打开一个新选项卡/窗口

[英]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;我需要帮助拨打 ajax 电话并使用响应打开新标签; 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 被多次调用,它将简单地替换第一个选项卡的内容,而不是打开另一个选项卡。

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?我怎样才能使它每次调用 function 时都会打开一个新选项卡?

Try this (url should be full qualified url, eg http://www.example.com/path/to/your/file/and/so/on )试试这个(网址应该是完全合格的 url,例如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");    
    })
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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