form id
을 views.py 페이지에 전달할 수 없습니다. jQuery는 'id'를보기 페이지로 전달하지 않습니다. 친절하게 말해서 내가 뭘 잘못하고 있는지 말해.jquery에서 양식 ID의 'id'를 가져 오는 방법
여기 내 jQuery입니다. 내가 if request.is_ajax()
조건을 제거하면 다음
$(function(){
$('.chatroom').submit(function() {
$.ajax({
type: "POST",
url: "/dashboard",
data : {
'chatroom_id' : $(this).attr('id')
},
});
});
이 Views.py
if request.is_ajax():
if request.method == "POST":
chatroom_id = request.POST['chatroom_id']
else:
chatroom_id =''
print chatroom_id
내 템플릿
{% for key, values in chat_data.items %}
<div class="container-fluid" alt = {{key}}>
<div class="row-fluid">
<div class="span2">
{{values.from}} <br/> {{values.init_query}}
</div>
<div class="span10 well">
{% for k in values.chat %}
<label> Text : {{k.text}} </label>
<label> {{k.date_time}} </label>
{% endfor %}
<form action = "#" method = "POST" id = {{key}} class="chatroom">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value = "Sent" class="btn btn-primary">
</form>
</div>
</div>
</div>
{% endfor %}
입니다, 그것은 다음 "Key 'chatroom_id' not found in <QueryDict: {u'reply': [u''], u'csrfmiddlewaretoken': [u'yIJct9O7WfyPnWmDosW9N5TEklRwoIHP']}>"
는 제거해야 마지막','은'data' 닫는 브라켓 –
당신은 페이지의 소스를 확인있었습니다? '{{key}} '값을 얻고 있습니까? –
아니요. –