最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - open response html in new tab browser - Stack Overflow

programmeradmin0浏览0评论

I have this code...

const handleMonitoring = async (noPKK) => {
  let body = {
  "MonitoringForm[nomor_pkk]": noPKK,
};

const config = {
    headers:{
      'Content-Type': 'application/x-www-form-urlencoded'
    }
}

axios.get( '' , body, 
       config)
.then( response => {
    console.log(response.data, "Monitoring");
})
.catch((err) => {
    console.log(err);
 });
}

and for response I get, like this... enter image description here

how I can open this "response" HTML in new tab browser...

I have this code...

const handleMonitoring = async (noPKK) => {
  let body = {
  "MonitoringForm[nomor_pkk]": noPKK,
};

const config = {
    headers:{
      'Content-Type': 'application/x-www-form-urlencoded'
    }
}

axios.get( 'https://monitoring-inaportnet.dephub.go.id' , body, 
       config)
.then( response => {
    console.log(response.data, "Monitoring");
})
.catch((err) => {
    console.log(err);
 });
}

and for response I get, like this... enter image description here

how I can open this "response" HTML in new tab browser...

Share Improve this question edited Jan 8, 2021 at 6:54 Imran Rafiq Rather 8,1681 gold badge19 silver badges40 bronze badges asked Jan 8, 2021 at 6:47 Dhies_tiraDhies_tira 111 silver badge4 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

If you want to open a new window with your own HTML, You can use the window.open method

const handleMonitoring = async (noPKK) => {
  let body = {
  "MonitoringForm[nomor_pkk]": noPKK,
};

const config = {
    headers:{
      'Content-Type': 'application/x-www-form-urlencoded'
    }
}

axios.get( 'https://monitoring-inaportnet.dephub.go.id' , body, 
       config)
.then( response => {
    let responseHtml = response.data;
    console.log(responseHtml, "Monitoring");
   //open the new window and write your HTML to it
    var myWindow = window.open("", "response", "resizable=yes");
    myWindow.document.write(responseHtml);
})
.catch((err) => {
    console.log(err);
 });
}

Link to the original answer

发布评论

评论列表(0)

  1. 暂无评论