EDITED
我正在尝试使用jquery / ajax来显示从django方法返回的数据.
我有一个名为keywordBtn的html按钮.因此,当按下它时,将调用updateKeywordSubscribed方法.
但是,我的目标不是由django返回的.我的方法有问题吗?
如果成功,div部分名称“update”将显示该json列表中的单词列表.
我的HTML中有什么:
我在views.py中的内容:
def keyword_subscribe(request):
if 'keyword_input' in request.POST:
if 'name_input' in request.POST:
xhr = request.GET.has_key('xhr')
response_dict = {}
new_keyword = request.POST['keyword_input']
username = request.POST['name_input']
response_dict.update({'keyword_input': new_keyword,'name_input': username})
power_keyword = subscribe_keyword(username,keywords)
if power_keyword:
response_dict.update({'success':True})
else:
response_dict.update({'errors':{}})
if not username:
response_dict['errors'].update({'name_input': 'User ID is required'})
if not total and total is not False:
response_dict['errors'].update({'keyword_input': 'Keyword field is blank'})
if xhr:
return HttpResponse(simplejson.dumps(response_dict),mimetype='application/javascript')
return render_to_response('r2/userprofile_list.html',response_dict)