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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:13:35+00:00 2026-06-12T07:13:35+00:00

I am working on a project with django and jquery and i have to

  • 0

I am working on a project with django and jquery and i have to implement comments like facebook and i dont have idea how to do it. Please i need your help and need you to be very specific with the code because i am a newbie.

Here is the code please tell me what i am missing.

Javascript

<script type="text/javascript">
    $(document).ready(function() {
      $('#category_form').submit(function(e) {
      e.preventDefault();
      $.ajax({
        type: 'POST',
        url: '{% url pos.views.add_category %}',
        data: $('#category_form').serialize(),
        dataType: 'json',
        success: function() {
          location.reload();
    $('#category_form').get(0).reset();
      },
     });
     return false;
     });
    });
</script>

Form

    class CategoryForm(ModelForm):
    name = forms.CharField(label=(u'Categoria'))
    class Meta:
     model = Category

Urls

    url(r'^category/$', 'pos.views.Categories'),

View

    def add_comment(request):
     if request.method == 'POST' and request.is_ajax():
      category_form = CategoryForm(request.POST)
      if category_form.is_valid():
       category = category_form.save(commit=True)
       category.save()
       json = simplejson.dumps(category, ensure_ascii=False)
       return HttpResponse(json, mimetype='application/json')
    return render_to_response(simplejson.dumps({'category': category,}),        context_instance=RequestContext(request), mimetype='application/json')
  • 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-12T07:13:36+00:00Added an answer on June 12, 2026 at 7:13 am

    Your view has two returns

    return HttpResponse(json, mimetype='application/json')
    return render_to_response(simplejson.dumps({'category': category,}),        context_instance=RequestContext(request), mimetype='application/json')
    

    Get rid of the one you don’t need. (It’s hard to tell what you need from the poorly formatted code.)

    Read the jQuery docs here: http://api.jquery.com/jQuery.ajax/

    Specifically, check out the Callback Function Queues section

    Change your javascript so ajax does something like this instead:

        $.ajax({
            type: 'POST',
            url: '{% url pos.views.add_category %}',
            data: $('#category_form').serialize(),
            dataType: 'json',
            success: function(data) {
                $("#results").html(data);
            }
                ...
    

    This uses the success callback to set the returned data (the json returned from your view) as the html data of the element with the ID “results” in your HTML.

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

Sidebar

Related Questions

I have a django project, but for some reason basic jquery isn't working. <html>
I am working on a Django project, where I need to implement full text
I'm working on a Django project that will need jQuery, jQuery UI , and
I'm working in django project. I have 1 postgresql sql file that need to
I have a django project that I have been working on as a solo
I need some opinions here. I'm working on a Django project using buildout to
I'm working in a project with django and GAE, but I need internationalization for
After working on a Django project for a while, I now have to do
I am working on a GAE Django Project where I have to implementing the
I am working on a django project and would like to include a slug

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.