我在 jquery 中使用 $.post 将请求发送到不同的页面。
<body>
<form id="saveuserFeedback" class="form" action="{% url saveFeedback %}" method="post" class="ajax"> {% csrf_token %}
...
...
<input type="submit" class="btn" id="Like" value="Like"/>
<input type="submit" class="btn" id="Discuss" value="Dislike"/>
...
</form>
<script type="text/javascript">
$(document).ready(function () {
$("#Like").click(function (e) {
e.preventDefault();
alert('Like clicked');
console.log('reached here');
$.post("saveFeedback2/", {
csrfmiddlewaretoken: document.getElementsByName('csrfmiddlewaretoken')[0].value,
feedbackStatus: "Like",
feedbackNoteID: "12345"
});
});
$("#Dislike").click(function (e) {
e.preventDefault();
alert('Dislike clicked');
console.log('reached here');
$.post("saveFeedback2/", {
csrfmiddlewaretoken: document.getElementsByName('csrfmiddlewaretoken')[0].value,
feedbackStatus: "Dislike",
feedbackNoteID: "12345"
});
});
});
</script>
但是在saveFeedback2中,数据好像不可用。只能看到csrfmiddlewaretoken通过了。
def saveFeedback2(request):
print request.POST
QueryDict: {u'csrfmiddlewaretoken': [u'18f0f434b876a3b742371c6b43222b4a']}>
以下是在 urls.py
url(r'saveFeedback2/$', saveFeedback2 , name='saveFeedback2'),
任何帮助表示赞赏。谢谢!