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

The Archive Base Latest Questions

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

Using jquery1.7.1 and django1.3 ,I was trying to make a post request through ajax,in

  • 0

Using jquery1.7.1 and django1.3 ,I was trying to make a post request through ajax,in some tutorial code I found on web

$(document).ready(function(){
    $("#create").click(create_note);

});

var create_note = function() {
  var title = $("#title").val()
  var slug = $("#slug").val()
  if (title != "" && slug != "") {
    var data = { title:title, slug:slug };
    console.log('title='+title);
    console.log('slug='+slug);
    var args = { type:"POST", url:"/create/", data:data, complete:done };
    $.ajax(args);
  }
  else {
    // display failure
  }
  return false;
};

The url “/create/” is mapped to django view

(r'^create/$','notes.views.create_note'),

def create_note(request):
    error_msg = u"No POST data sent."
    if request.method == "POST":
        post = request.POST.copy()
        if post.has_key('slug') and post.has_key('title'):
            slug = post['slug']
            if Note.objects.filter(slug=slug).count() > 0:
                error_msg = u"Slug already in use."
            else:
                title = post['title']
                new_note = Note.objects.create(title=title,slug=slug)
                return HttpResponseRedirect(new_note.get_absolute_url())
        else:
            error_msg = u"Insufficient POST data (need 'slug' and 'title'!)"
    return HttpResponseServerError(error_msg)

When I click the submit button,which triggers the javascript function create_note ,I get a 403 error. Must be the csrf problem..

I tried to solve this by modifying the ready function

$(document).ready(function(){
        $.ajaxSetup({
        data: {csrfmiddlewaretoken: '{{ csrf_token }}' },
    });
        $("#create").click(create_note);

    });

but it didn’t work..I still get 403 error

So,I tried to modify the data in ajax call

var create_note = function() {
    var data = { title:title, slug:slug ,csrfmiddlewaretoken: '{{ csrf_token }}'};
    ...
    var args = { type:"POST", url:"/create/", data:data, complete:done };
    $.ajax(args);

};

Still it causes 403 error..

Please tell me what should be done to correct this..I saw the
django doc about this,but I am confused how to make use of that.Should I copy the entire jQuery(document).ajaxSend(... code in to my javascript file..I am really confused here..

  • 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:17:34+00:00Added an answer on June 3, 2026 at 9:17 pm

    You need to (as the document you linked to suggests) copy that entire ajaxSend method …

    You dont need to modify it in any way – it is a complete solution – the ajaxSend method is actually an event handler for the ajaxSend event. Its triggered when you use the .ajax method in jQuery. See the ajaxSend docs here

    The method linked in the above document appends the correct X-CSRFToken header to your AJAX request. You can then use your first method for sending the AJAX request.

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

Sidebar

Related Questions

I'm trying to learn some basic ajax using Django. My simple project is an
I'm trying to get some AJAX running with Django using jQuery. The problem is
am new to jquery.I am doing some ajax using jquery in django. $(document).ready(function() {
Using Django, I want to make some data available for download. My jQuery call
I'm trying to write a simple search server, using Django with AJAX. The server
Looking to get some insight and tips on using ajax with django. Say I
I'm developing a web page using django and I want to add some javascript
I'm trying to make a pull down menu post a form when the user
So, I'm trying to make a simple call using jQuery .getJSON to my local
To teach myself Javascript, I'm trying to make a web page that gives users

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.