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

3
  • For one thing, you need a value for the URL, not an empty string. Commented Apr 16, 2022 at 14:59
  • Note that from the point of view of the JavaScript, it doesn't matter that the server is written with Django. The JavaScript only knows how to make an HTTP request and doesn't care what language actually implements it. Commented Apr 16, 2022 at 15:00
  • Also, be sure that you set the correct headers in the request, especially Content-Type. Commented Apr 16, 2022 at 15:01

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.