I have recently been working on implementing an ajax based file uploader for my small blog site. I also have a small form (on the same page as the ajax file uploader) which collects basic details such as name, email id etc.. Now, the problem I’m facing is that when a user uploads a file though the ajax uploader and completes the form, I am not able to get the “file name” of the uploaded file.
Basically, I would like to write out the file name from the ajax upload to my form field. The upload by itself works fine, and I am also able to see the POST messages through firebug. So, I can see some JSON like:
{
"path": "/media/uploads/paperscience_5055721894547287.pdf",
"success": true,
"filename": "paperscience_5055721894547287.pdf"
}
and I would like to get the “path” parameter into my form field named filenames.
My django code is here
I would appreciate any guidance to achieve the above.
In your response function:
Add the filename to your form filenames field (assuming the field has id: id_filenames):
If you want to resubmit this, you can add a number of hidden fields with your form containing the filenames. Just append the hidden fields to the form and when the user submits, this will be part of your POST data.