【发布时间】:2014-06-26 03:47:16
【问题描述】:
我正在尝试使用 Django 进行 ajax 请求,但我收到内部服务器错误 500..令人惊讶的是,请求将发送到服务器,但当它尝试返回我猜想的响应时它失败了..
这是我的看法
views.py
@csrf_exempt
def getproductinfo(request):
to_json = {'name':'test'}
print "Value of a = ", to_json
try:
json_response = simplejson.dumps(to_json)
except (TypeError, ValueError) as err:
print 'ERROR:', err
print 'json_response = ', json_response
return StreamingHttpResponse(json_response,content_type='application/json')
ajax 调用
$.ajax({
async:false
,url:'/getproductinfo'
,type: 'POST'
,data: {session_id: '{{request.session.sessionid}}'}
,success: function(msg){
alert('Success')
}
,error: function(msg){
alert("It erroed out")
}
})
urls.py
url(r'^getproductinfo',getproductinfo),
请告诉我如何解决此问题..谢谢..
【问题讨论】:
-
如果您发布您遇到的错误以便人们可以帮助您解决它会更好。
-
当你在浏览器中直接输入 url 时,Django 会告诉你什么?另外,您为什么使用 StreamingHttpResponse 而不是 HttpResponse?您希望您的产品信息那么那么大吗?
-
@Emma:当我直接键入链接时,我收到了这个错误 - “未定义全局名称'StreamingHttpResponse'”......所以,我改变了 HttpResponse 并且它现在可以工作了......是的,我productinfo 可能很大,这就是我使用它的原因...用户输入有帮助...