Javascript 从jQuery调用python文件调用';错误';即使在成功执行之后
我尝试使用AJAX调用python文件,该文件将基本的“hello”返回到HTML文件 我面临的问题是,AJAX的“错误”部分即使在成功执行之后也会被调用 AJAX请求Javascript 从jQuery调用python文件调用';错误';即使在成功执行之后,javascript,jquery,python,ajax,cgi,Javascript,Jquery,Python,Ajax,Cgi,我尝试使用AJAX调用python文件,该文件将基本的“hello”返回到HTML文件 我面临的问题是,AJAX的“错误”部分即使在成功执行之后也会被调用 AJAX请求 $.ajax({ 'url': 'http://localhost/keywordSearch.py', 'success': function(response){ alert(response.responseText); }, 'error': function(error)
$.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文件:sample.py
#!/Python27/python
print "Content-type: text/html;charset:utf-8"
print
print "hello"
我们在html控制台中得到的输出是“hello”,表示它来自“error”,如果它来自alert,则表示“success”
我不明白为什么像这样的基本程序也会执行“错误”,
感谢您的帮助打开explorer的
调试器
,单击网络
查看的响应标题
http://localhost/keywordSearch.py
,状态2xx/3xx?
状态200 OK@cheney如果您在控制台中收到此消息,XMLHttpRequest无法加载http://localhost:8000/web/show. 请求的资源上不存在“Access Control Allow Origin”标头。起源'http://127.0.0.1:8000因此不允许访问。
或者换句话说,您的html的url与http://localhost/xxx
,如果是,请参阅;或者,您可以将本地url与静态html页面一起使用,以查看出错的部分。