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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:46:20+00:00 2026-06-14T13:46:20+00:00

I am trying to POST data using jQuery/AJAX in Django and am having trouble.

  • 0

I am trying to POST data using jQuery/AJAX in Django and am having trouble. When I run the code below and click on the ‘test’ button, the entire page re-loads again, which isn’t what I want to happen (that’s why I’m using AJAX).

I’m also not able to confirm the AJAX request is getting to the Django view.

EDIT: I’ve made the edits for return false and event.preventDefault(). A new page doesn’t load, but I’m still not able to see the updated text in the <div id='message'> field. I’m not sure if the data is getting sent. I’m seeing in the console:

POST /edit_favorites/ HTTP/1.1" 403 2294

views.py:

from django.shortcuts import render_to_response
from django.http import HttpResponse

def edit_favorites(request):
    if request.is_ajax():
        message = "Yes, AJAX!"
    else:
        message = "Not Ajax"
    return HttpResponse(message)

urls.py:

url(r'^edit_favorites/', 'edit_favorites'),

HTML:

<form method='post' id='test'>
  <input type="hidden" value="video34"/>
  <input type='submit' value='Test button'/>
  <div id='message'>Initial text</div>
</form>

JavaScript:

$(document).ready(function () {
  $("#test").submit(function (event) {
    event.preventDefault();
    $.ajax({
      type: "POST",
      url: "/edit_favorites/",
      data: {
        'video': $('#test').val() // from form
      },
      success: function () {
        $('#message').html("<h2>Contact Form Submitted!</h2>")
      }
    });
    return false;
  });
});

Any advice?

  • 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-14T13:46:21+00:00Added an answer on June 14, 2026 at 1:46 pm

    Misplaced return false;. It should be at the end of .submit() function. So move it one line upwards:

    $(document).ready(function () {
      $("#test").submit(function (event) {
        $.ajax({
          type: "POST",
          url: "/edit_favorites/",
          data: {
            'video': $('#test').val() // from form
          },
          success: function () {
            $('#message').html("<h2>Contact Form Submitted!</h2>")
          }
        });
        return false; //<---- move it here
      });
    
    });
    

    UPDATE:

    About the issue POST /edit_favorites/ HTTP/1.1" 403 2294. Check on this post which looks similar to your issue:

    • Django jQuery post request
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im having trouble trying to post data correctly using jQuery/AJAX I have the following...
I am trying to post data using ajax in jquery of json datatype. I
I'm trying to call an asp.net method using jquery/ajax from a button click on
I am trying to learn how to post some data using $.ajax through jquery
I am trying to post some data with jQuery Ajax, but the parameters in
I'm trying to use jquery.Ajax to post data to an ASP.NET MVC2 action method
I was trying to grab some data from the database using JQuery AJAx, and
I am trying to submit data using Jquery AJAX (using the following script) and
I'm trying to return XML-data from a Python script using jQuery's .ajax: <html><head> <script
I have crated a form and trying to insert data using jquery ajax. But

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.