Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

337
Views
Send messages from Django to Ajax while processing the request

I'm making an AJAX call to a Django POST view. It's reading X files locally, and then sending back to the front-end (thanks to ajax), so the user can download them.

Everything is working fine on this part, but i'd like to have some sort of "intermediate response", which would tell Ajax each time the server reads one file.

That way, i could create a loading bar on the front end while the server is processing the request.

Is there any way i could do it, using ajax, or something else (anything would be fine, as long as i'd keep my ajax request somewhere).

Here is my code, quite simplified, so you can understand better what I'd like it to do:

Django:

def downloadFiles_API(request):
    if request.is_ajax and request.method == "POST":
        requested_files = json.loads(request.body)['files']
        for file in requested_files:
            # Handle file reading (this part works)
            # Here i'd like to tell the front end "File X has been loaded..." (for each file)
        # Zip-ing all files, and send it as response
        return FileResponse(myZipFile)

AJAX:

$.ajax({
        url: "/api/downloadFiles/",
        type: 'POST',
        contentType: "application/json; charset=utf-8",
        data: JSON.stringify({
            "files" : filesThatTheUserWants,
        }),
        xhrFields:{
            responseType: 'blob'
        },
        success: function (response){
            // Download the file in response (this works)
        },
        // And what i'd like to add (it's NOT in my code):
        onProgress: function (intermediateResponse){
            console.log(intermediateReponse);
            // Would print "File X has been loaded..."
            // Each time a file is loaded on server side
        }

Note: I found some similar questions, but they are either too generic, or not explaining the ajax part (like these: Send intermediate messages during an Ajax call, or How to stream an HttpResponse with Django)

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!