Here is my Html code:
<html>
<head>
<title>aerator</title>
</head>
<body>
<div id="train"></div>
<div id="predict"></div>
Here is my Javascript. I am trying to get the data using XMLHttpRequest for every certain set of interval for 2 variable to later using each of them to update the html with div id train and predict
$(document).ready(function(){
refresh();
});
function refresh()
{
setTimeoutfunction(){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("predict").innerHTML = this.responseText;
}
};
xhttp.open("POST", "http://127.0.0.1:5000/predict", true);
xhttp.send();
}, 1100);
setTimeout{function(){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("train").innerHTML = this.responseText;
}
};
xhttp.open("POST", "http://127.0.0.1:5000/train", true);
xhttp.send();
}, 3000);
}
Below is my python flask code. I am including the needed function which i refer on my javascript code above. Edit : I actually have tried both POST and GET method and both is not retrieving data.
@app.route("/predict")
def mainPrediksi():
predict = preprocessing('root','','127.0.0.1','database')
if(condition):
X = 'option1'
else:
X = 'option2'
return (X,str(datetime.now()))
@app.route("/train")
def mainTrain():
X_train,X_test,Y_train,Y_test = preprocessing('root','','127.0.0.1','database')
X_train = X_train.astype(float)
Y_train = Y_train.astype(float)
#train classifier
model = train_clf(X_train,Y_train)
# save the model to disk
filename = 'randomForest.sav'
joblib.dump(model, filename)
return ('Success Train Model',str(datetime.now()))
I am expecting that my XhttmlRequest to get the return value from /predict and /train, but from what I see in my terminal it seems to only post request and not getting any response. t Is there anything that I did wrong? thank you