python - How can I catch server json response while uploading image using Ajax? -
I have a form that is loaded by jQuery from an external template file:
< Code> $ ('#imguploadform') Html ('& amp; nbsp;') Load ('{% url upload_form%}');
The template looks like this:
& lt; Img src = "{{MEDIA_URL}} img / misc / upload.png" alt = "illustration" title = "myimage" /> & Lt; Form id = "uploadform" enctype = "multipart / form-data" method = "post" action = "upload_pictures /" & gt; {{Form.as_ul}} & lt; Input type = "submit" value = "upload" id = "upload image" /> & Lt; / Form & gt;
I am trying to upload an image with Ajax using the jquery form plugin:
var submit_options = {target: '# picworks ', Data Type:' Json ', Success: Work () {Alert (' This Works! '); }}; $ ('# UploadForm'). Submit (function () {$ (this) .jax submit (submit_option); return back;});
But then I want to return a Jason object from the server and want to load the page in a dynamically way so that its address can be returned. I have tried this way:
def upload_picture (request): dest = save_original (request.FILES ['image']) Form = UploadImageForm (request.POST, request.FILES) res = Json.dumps ({"path": dest,}) HttpResponse (res, mimetype = 'application / json'))
The problem is that I can not capture in Jason Javascript So, my browser shows me just an empty page with json dictionary content, am I doing wrong?
Take a parameter of your success callback This response will be.
Comments
Post a Comment