【发布时间】:2010-12-01 05:40:34
【问题描述】:
我的 ajax 代码:
$.ajax({
type: 'POST',
url: URL + "xyz/" ,
data: {"email": email},
success: function(data) {
alert('hello')
},
dataType: "json",
});
我在 python + Bottle 框架中的处理程序:
def index():
if request.POST == XMLHttpRequest:
email = request.GET.get('email')
response.COOKIES['email'] = email
if check_email(email): //a method written for checking email
return some template
else:
return False //here i want to return some error message to ajax. How to
做吗?以及如何在 ajax 中捕获错误。
抛出错误:NameError("global name 'XMLHttpRequest' is not defined",) 是瓶子支持吗?
【问题讨论】:
-
你从哪里复制的?大多数 Python 行没有任何意义......
-
NameError 是因为您没有定义 XMLHttpRequest,您可能需要从某个地方导入它。另外,我的猜测是 XMLHttpRequest 是一个类,如果是这样,您可能想使用 'isinstance(request.POST, XMLHttpRequest)' 而不是 '==' 比较。