1👍
✅
This will work for you..
<script type="text/javascript">
var frm = $('#FORM-ID');
frm.submit(function () {
$.ajax({
type: frm.attr('method'),
url: frm.attr('action'),
data: frm.serialize(),
success: function (data) {
$("#SOME-DIV").html(data);
},
error: function(data) {
$("#MESSAGE-DIV").html("Something went wrong!");
}
});
return false;
});
</script>
<form action="{% url 'myapp.views.add_bet' %}" method="post" id="#FORM-ID">
{% csrf_token %}
<input type="hideden" name="off_id" value="{{offer.id}}">
<button class="btn btn-default add" type="submit" >Add »</button>
</form>
def add_bet(request):
off_id=request.POST.get('off_id',None)
b=Bet(offer=offer, user=request.user, submitted=False)
b.save()
return redirect('myapp.views.index')
Source:stackexchange.com