jquery - How to send django text and picture form by ajax -


what trying sending user's text with/wihtout picture , response them page without reload page again.

django form:

class postform(forms.modelform): text = forms.charfield(max_length=128) picture = forms.imagefield(required=false) class meta:     model = post     fields = ['text', 'picture',] 

html:

<form id="post_form" enctype="multipart/form-data">     <div class="fieldwrapper">         {% csrf_token %}          {{ postform.as_p }}    </div>    <input id="postbtn" type="submit" name="submit" value="submit"/> </form> 

jquery:

$("#postbtn").click(function() {     $.ajax({            type: "post",            url: "/restaurant/feed/",            data: $("#post_form").serialize(),            success: function(data)            {                 //            }     }) } 

views:

def feed(request):  print request.files 

a result got print empty list. suggestion? way can upload picture without ajax method.

you can't send files via jquery $.ajax(), should go other solution then, http://blueimp.github.io/jquery-file-upload/ or https://github.com/widen/fine-uploader


Comments