我已经用HTML代码制作了Django Form如何进行Ajax调用。我是Ajax的新手。问题是当我们输入内容时,输出就会出现,但是形式是不可见的。如果ajax调用它,那么一切都会很好
forms.py
from django import forms
class ReportForm(forms.Form):
text = forms.CharField(widget=forms.Textarea(attrs={'rows': 5, 'cols': 100}))
html
{% extends 'base.html' %}
{% block content %}
<h1>StopWordsRemoval</h1>
<div>
<form action = "" method = "post" >
{% csrf_token %}
{{ form.as_p}}
<button type="submit">stopwordsremoval</button>
</div>
<div >
<ul>
<li>{{ naturallanguageprocessing }}</li>
<a href="{% url 'stopwordsremoval' %}" </a>
<style>
div {
width: 1000px;
border: 5px solid green;
padding: 10px;
margin: 10px;
}
</style>
</div>
</div>
{% endblock %}
答案 0 :(得分:1)
这应该使您入门:
<script type='text/javascript'>
$(document).ready(function(){
$(form).on('submit', function(event){
$.ajax({
url: // where do you want the form sent?
type: 'POST',
data: this.serialize(),
});
});
});
</script>