I am trying to use AJAX to call a python file which returns a basic "hello" back to HTML file.
The Problem I'm facing is, the 'error' section of the AJAX gets called even after successful execution,
AJAX request
$.ajax({
'url': 'http://localhost/keywordSearch.py',
'success': function(response){
alert(response.responseText);
},
'error': function(error){
$('.table-responsive').html('');
$().toastmessage('showToast', {
text : 'Unable to get data now. Please try after sometime.',
sticky : false,
stayTime : 2000,
position : 'middle-center',
type : 'warning'
});
console.log(error.responseText);
}
});
Python file:sample.py
#!/Python27/python
print "Content-type: text/html;charset:utf-8"
print
print "hello"
The output we get in html console is "hello", indicating that it's coming from 'error', if it came through alert, it would mean 'success'.
I don't understand why 'error' is executed even for a basic program like this, Thanks for the help