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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:43:39+00:00 2026-05-16T12:43:39+00:00

This is kind of I already lost x hours debugging this kind of problem/question

  • 0

This is kind of “I already lost x hours debugging this” kind of problem/question 🙁

Following jQuery js code is initiating POST request upon button click

$("#btn_create_tag").click(function(evt) {
$.post("/tag/createAjax", { 
    tagname: $("#txt_tag_name").val()       
    },
    function(data) {
    }
);
});

Django code that is performed on this call is:

@suppress_logging_output
@login_required
def createAjax(request):
    if request.is_ajax() and request.method == 'POST':
        tagName = request.POST["tagname"]
        new_tag = Tag()
        new_tag.name = tagName
        new_tag.save()
        print "new tag with id %s has been created" % new_tag.id

That code is executed successfully (I’m doing checks for empty or already existing name, but didn’t wrote here to be more clear), but new Tag object is NOT created.
I’m even getting “”new tag with id %s has been created” printed on devserver’s prompt, and every time ID is increased for one, as suppossed to, but objects are not stored in db.

When I execute

new_tag = Tag()
new_tag.name = tagName
new_tag.save()

from Django shell, new Tag object is regulary created, but from jQuery request, it’s not created.

Have any idea what’s wront, what to check, how to debug this….

DB behind is PostgresSQL 8.3.

Any suggestion is more then welcome 🙂

Update:

I wrote UnitTest which is working:

class AjaxTestCase(TestCase):
    def testAjaxCreateTag(self):
        tagNum = Tag.objects.filter(name="TEST_TAG").count()
        self.assertEqual(tagNum, 0)
        c = Client()
        c.post('/lookup/tag/createAjax', {'tagname': 'TEST_TAG'}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        tagNum = Tag.objects.filter(name="TEST_TAG").count()
        self.assertEqual(tagNum, 1)

Update2:

Hum, this morning, it seems that everything is working fine, but code hasn’t changed. I don’t like this at all 🙁

  • 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-05-16T12:43:40+00:00Added an answer on May 16, 2026 at 12:43 pm

    This sounds very strange. Can you double check your database settings? Ensure that you are using the correct database inside settings.py? Also write an unit test to exercise the code using Django’s test client. In your test method remember to send the HTTP_X_REQUESTED_WITH header for is_ajax() to work.

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

Sidebar

Related Questions

This kind of builds up on Already asked question ... However here, say, I'm
I know this kind of questions have been asked already many times before. The
I want to rollback a transaction which already committed, does JTA support this kind
I'm sorry if this was already answered, but it's kind of difficult to search
This kind of code would normally work in PHP, but since the scope is
I perform this kind of query in my Python code to conn = rdbms.connect(instance=_INSTANCE_NAME,
I have this kind of question. In my form, i got this as a
I already know there's answers for this kind of thing, but I don't really
Kind a simple problem, but i am completely lost on how to approach to
I need help to rewrite my URL, already user posted this kind similar questions

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.