I have the following files HTML:
<!DOCTYPE html>
<html>
<body>
<input id = "input_thing">
<button id="demo" onclick="myFunction()">Click me.</button>
<script src='script.js'></script>
JS:
function myFunction() {
var x = document.getElementById("input_thing").value;
const Http = new XMLHttpRequest();
const url=' https://*****.****.**/doctorapi/'+x;
fetch(url).then(function (response) {
console.log(response.json());
document.getElementById('demo').innerHTML=response.json();
})
}
Essentially I'm trying to print the response to a request I send. The website which I created is receiving requests.
Here is some of that code
@app.route('/doctorapi/<query>')
def next(query):
respons = query_search(query)
respons=str(respons)
response = make_response(jsonify(
{
"medical_response":respons,
"query":query
}
))
return response
and when I go on my browser, I see the response. However, the JS isn't getting that JSON and logs and empty string. How do I fix this? What's the correct way of sending a request>