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 8922661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:54:02+00:00 2026-06-15T06:54:02+00:00

I am working on a Django app and I’m having an issue with ajax

  • 0

I am working on a Django app and I’m having an issue with ajax and jQuery.

On my page, I have a javascript function that is called when a button is clicked. The purpose of this function is to make an ajax
call to a django view method. In this method some logic is done using some POST data which was sent with the AJAX call, and if the operation was successful, I want to return to
another page, otherwise, I simply want the user to remain on the same page, and a notice will be presented to the user using javascript.

below is a snippet of code:

(Javascript)

function makeCall() {

    $.post(url, data, function(data) {

          if(data=="ERROR") {

             alert("THERE WAS AN ERROR");

          } else {

             //send user to a new page. 
          }
    });
}

(Django-Python)

def viewMethod(request):

   //LOGIC...  Renders page using POST data.

    if success:

        //... preparing the response.

        return HttpResponse(t.render(c))
    else:

        return HttpResponse("ERROR", content_type="text/plain")

How can I present the response page to the user using javascript/jQuery in the case that the operation is a success?

Thanks

  • 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-15T06:54:03+00:00Added an answer on June 15, 2026 at 6:54 am

    In the viewMethod, you can render page using POST data but not the whole page, that is ,the page you will respond just has the body tags not the head.

    if success:
        return HttpResponse('<body><p>SUCCESS</p></body>')
    

    and in front-end

    $.post(url, data, function(data) {
    
          if(data=="ERROR") {
    
             alert("THERE WAS AN ERROR");
    
          } else {
    
             $('tip').append(data)
          }
    });
    

    if you still use the whole page, its formal like this: , you can use window.open or iframe tag to handle it.
    But I advise just respond some snippets of html.

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

Sidebar

Related Questions

I have a standalone Django app that I'm working on right now. You can
I'm working on a django app for a site that requires an image gallery.
I have been working on a django app on my local computer for some
I'm working on a simple message board app in Django that lets people upload
I have a small app I'm working on where I'm trying to use Django's
I am working on a django app that needs a directory to download and
I am working on a Django app and I have a class which reads
A Django app that I am working has an Event model. An Event may
I'm working on a Django app that occasionally throws a ViewDoesNotExist exception when trying
I am working on a simple django app that allows users to create posts

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.