0

Any ideia how to upload File (.pdf) from ajax to django backend ?

customerForm.addEventListener('submit', e => {
e.preventDefault()
$.ajax({
    type: 'POST',
    url: '',
    data: {
        'csrfmiddlewaretoken': csrf[0].value,
        'identity_type': $('#id_identity_type').val(),
        'identity_number': $('#id_identity_number').val(),
        'file': $('#id_file').val()
    },
    success: function(response) {
        console.log('SUCCESS')
    },
    error: function(error) {
        console.log(error)
    }
})

Thank You

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
Mar_TO
  • 183
  • 1
  • 3
  • 9

1 Answers1

1

There are a lot of ways but Here's a link it's simple I think

https://www.youtube.com/watch?v=g3h1OC3S5Lo

He/She explains how to upload file using ajax.

Alasgar
  • 134
  • 9