Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7932599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:04:02+00:00 2026-06-03T21:04:02+00:00

I’m working with Django. I have an HTML page, where I do some Javascript

  • 0

I’m working with Django. I have an HTML page, where I do some Javascript stuff, and then I do a jQuery post, in this way:

$.ajax({ 
  url: '/xenopatients/measurement/qual', 
  type: 'POST', 
  data: {'obj':data}, 
  dataType: 'json', 
  contentType: "application/json; charset=utf-8", //questo ok 
}); 

After this post request, my Django view correctly handles the call for this URL.
What I want it to do is process the data, send the user to another page, and send this data to the new page.
The problem is that I cannot perform the redirect like usual in Python, it’s like the code ignores the redirect.

My Python code is:

@csrf_protect 
@login_required#(login_url='/xenopatients/login/') 
def qualMeasure(request): 
    name = request.user.username 
    print "enter" 
    if request.method == 'POST': 
        print request.POST 

        if "obj" in request.POST: 
            print 'obj received' 
            return render_to_response('mice/mice_status.html', RequestContext(request)) 

    return render_to_response('measure/qual.html', {'name': name, 'form': QualMeasureForm()}, RequestContext(request)) 

The only way I’ve found to change the page is through Javascript after the code above:

top.location.href = "/xenopatients/measurement";

But I don’t know how to pass the data I need when using this method.

The HTML code:

<form action="" method=""> 
  <table id="dataTable" width="100%" border="1"></table><br> 
  <script language="javascript"> 
    document.measureForm.id_barcode.focus(); 
    document.measureForm.Add.disabled = false; 
    $('#dataTable').tablePagination({}); 
  </script> 
  <input type="button" name="save" value="Save Measure Serie" onclick="table2JSON('dataTable')"/> 
</form> 

P.S. I’ve also tried $.post, but with the same results.

How can I do a redirect after a post request made with jQuery in Django?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T21:04:03+00:00Added an answer on June 3, 2026 at 9:04 pm

    Ok, I’ve found the magical solution! 🙂

    The situation:
    there is a view’s method called by jQUery.ajax()

    To redirect after Ajax, I’ve used the tips found here (use document instead of ‘body’ in the jQuery selecotor)

    But, I’ve had also further operations to do.

    in the called view, call another method, like this:

    [...]
    if request.method == 'POST':
        if "obj" in request.POST: #ricevuti dati da ajax
            request.session['qual'] = request.POST['obj']
            return HttpResponseRedirect(reverse("xenopatients.views.qualReport"))
    

    I save the data that I need in the session. I use this data in the called view.

    Call another method it’s the key for redirect the page of the browser.
    In fact, at the end of the called method, you can normally write&execute:

    return render_to_response('measure/qualReport.html', {'name':name, 'list_report': report, 'message':'Measures correctly saved'}, RequestContext(request))
    

    Hope this can be useful for someone! 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.