Currently, I am working with Flask using Python. My goal is to return HTML table rows in an AJAX call from the Flask method.
The HTML page contains:
<div>
<table id="tableQuestions">
</table>
//AJAX Requests to get
function loadQuestions() {
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
alert(xmlHttp.readyState + " " + xmlHttp.status);
if (xmlHttp.readyState==4 && xmlHttp.status == 200) {
var response = xmlHttp.responseText;
console.log(response);
document.querySelector("#tableQuestions").innerHTML=response;
}
xmlHttp.open("GET", '/gS', true);
xmlHttp.send(null);
}
}
The Flask route is as follows:
#test.mix() returns html table rows
@gbp.route('/gS')
def gS():
test=mn()
response = make_response(test.mix(quesCount=4),200)
response.mimetype="text/html"
While inspecting in Safari debugger, I noticed that although the responseText
displays the table data from the server, the readystate
remains at 1 and status
is 0.
https://i.sstatic.net/Azm1s.png
Any suggestions on how I can resolve this issue would be greatly appreciated.