I have an ajax call that looks like this;
$.ajax({
type : 'GET',
url: 'url',
data: 'data='+data,
success: function(configOut) {
alert(configOut);
},
error: function(configOut) {
alert(configOut);
}
});
The view that is invoked does this:
command = ['python', 'autoDeploy.py']
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
out = p.stdout.read()
rv = p.wait()
if rv:
status = 400
else:
status = 200
return HttpResponse(out, content_type="text/plain", status=status)
In the debugger I can see that I'm returning this:
(Pdb) print HttpResponse(out, content_type="text/plain", status=status)
Content-Type: text/plain
Invalid file format. Format is: "Toolname,Type,IPaddress,login,pw"
But in my success or error function I cannot seem to access that text. configOut has:
Object {readyState: 0, setRequestHeader: function, getAllResponseHeaders: function, getResponseHeader: function, overrideMimeType: function…}
How do I get at the text that is being returned?
Something I just noticed is that in the Chrome developers tools, in the network tab for this request, in the Status/Text column, it says "(cancelled)" - not sure what that means. If I run the same request from my browser I do get a response.
I debugged this further and found that on the server side I am getting 'error: (32, 'Broken pipe')' Googling that revealed that it's because the browser has already moved on, so there is nothing to receive the response. I've tried setting the timeout to a large value, but no joy. How can I prevent that? It seems it is not possible to do a synchronous request from the browser.