Hi,
I have been having a problem with AJAX HTTP POST requests. I am using the Flask framework with AJAX to communicate between client and server.
When submitting a POST request, it is being received in the Python code, however the response is not being recieved by the client. After waiting 300 seconds, the request times out and I receive a 499 error code (client time out). The code runs fine on my personal machine, so it must be a networking problem.
AJAX code:
function setNetwork(){
var $SCRIPT_ROOT = {{ request.script_root|tojson|safe }};
var networkType = document.getElementById("networkSelect").value
if(networkType != "none"){
$.ajax({
type: "POST",
url: $SCRIPT_ROOT + "/setNetwork/",
data: networkType,
success: function(response) {
console.log(response)
}
}
);
}
}
Python code:
@app.route('/setNetwork/',methods=['GET','POST'])
def setNetwork():
'''Set the network to make the prediciton.
Returns:
The type of network to be used.
'''
data = request.get_data()
print(str(data))
set_network(str(data))
print("setNetwork ok")
return(data)
Access log error code:
[21/Apr/2018:19:56:55 +0000] "POST /setNetwork/ HTTP/1.1" 499 0 "http://georgelancaster.pythonanywhere.com/guest" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0" "86.20.42.188" response-time=300.000