I am facing an issue with my javascript function that sends a signal to my flask app for recalculating figures using ajax. Upon successful figure production, I want to reload the page with updated figures by adding a version number to the filename (using '?') to enforce the reload process. Here is a snippet of my code:
$.ajax({
url: $SCRIPT_ROOT + "/process_figures",
type: "POST",
async: true,
cache: false,
dataType: 'json',
contentType: "application/json; charset=utf-8",
data: JSON.stringify({}, null, '\t'),
success: function(data){
if(data.error){
console.log('Error = ', data.error)
}
else{
var images = document.getElementsByClassName('metric_img');
for(i = 0; i < images.length; i++){
images[i].src = images[i].src.split("?")[0] + '?version=' + new Date().valueOf();
}
window.location.reload();
}
}
});
However, this codes leads to an error message like:
127.0.0.1 - - [20/Nov/2017 14:59:39] "GET metrics_indices_1.png?version=1511189978191 HTTP/1.1" 200 -
Error on request:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/werkzeug/serving.py", line 205,
in run_wsgi
execute(self.server.app)
File "/usr/local/lib/python2.7/site-packages/werkzeug/serving.py", line 196,
in execute
write(data)
File "/usr/local/lib/python2.7/site-packages/werkzeug/serving.py", line 164,
in write
self.send_header(key, value)
File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/BaseHTTPServer.py", line 412, in send_header
self.wfile.write("%s: %s\r\n" % (keyword, value))
IOError: [Errno 32] Broken pipe
Can anyone help me identify what might be causing this error? Also, I would appreciate assistance in reloading only the images using Javascript without having to refresh the entire page.