I am trying to print on an html page the response from a REST request with JS, but when I return the string on the html page is not replaced.
JS code
function sendDELrequest() {
serviceID = $("#serviceID").val();
var myurl = "/api/microservice/"+serviceID;
$.ajax({
method: "DELETE",
url: myurl,
success: function (response) {
Resp(response);
},
});
}
function Resp(r) {
resp=open("response.html").read();
resp = resp.replace(/__RESPONSE_VALUE__/g, r.text);
document.location.href = '/response';
}
HTML
<head>
<meta charset="utf-8" />
<title>Patient Monitoring - Response</title>
<link rel="shortcut icon" type="image/png" href="/img/healthcare.png">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<p> </p>
<p> </p>
<div class="container">
<p> </p>
<h3 style="text-align: center;">__RESPONSE_VALUE__</h3>
<p> </p>
<p style="text-align: center;">
<input type="button" class="button" onclick="document.location.href='/';" value="Homepage"><br></p>
</div>
</body>
You can set only html value when getting success after ajax . Select using ID where you want to show the results
$("#id").html()