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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:38:43+00:00 2026-06-14T00:38:43+00:00

I am using AjaxForm plugin to submit my form without refresh. like: $(‘#my_form_id’).ajaxForm(function(){ //something

  • 0

I am using AjaxForm plugin to submit my form without refresh. like:

$('#my_form_id').ajaxForm(function(){

        //something on success or fail
    });

this works correctly. when i click submit button it saves form datas without refresh. But before this ; i had django messages on my template file like:

{% for message in messages %}
    <div id="notice" align="center">
        {{ message }}
    </div>
{% endfor %}

what this code does is displaying notifications if post saved correctly or something failed.

now; i can’t do that. i dont understand how i can use these messages tags with ajax functions.

it just saves the post. no notifications.

thank you.

edit :

add_post url : url(r'^admin/post/add/$', view='add_post',name='add_post'),

related view :

@login_required(login_url='/login/')
def add_post(request):
    template_name = 'add.html'
    owner = request.user
    if request.method == "POST":
        form = addForm(request.POST)
        if form.is_valid():
            titleform = form.cleaned_data['title']
            bodyform = form.cleaned_data['body']
            checkform = form.cleaned_data['isdraft']

            n = Post(title=titleform, body=bodyform, isdraft=checkform, owner=owner)
            n.save()
            messages.add_message(request, messages.SUCCESS,
                'New post created successfully!')
        else:
            messages.add_message(request, messages.WARNING,
                'Please fill in all fields!')
    else:
        form = addForm()
    return render_to_response(template_name, {'form': form, 'owner': owner,},
        context_instance=RequestContext(request))
  • 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-14T00:38:44+00:00Added an answer on June 14, 2026 at 12:38 am

    These are the tools/methods that helped me to solve the problem. First, I have a helper utility method called render_to_json:

    # `data` is a python dictionary
    def render_to_json(request, data):
        return HttpResponse(
            json.dumps(data, ensure_ascii=False),
            mimetype=request.is_ajax() and "application/json" or "text/html"
        )
    

    I have a messages.html template to render the necessary html for the popup message(s):

    {% for message in messages %}
    <li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
    {% endfor %}
    

    When create a message in response to an AJAX request, I use Django’s render_to_string to package the message(s) into a string that gets stored in a data dictionary, which then uses my render_to_json to return an appropriate response:

    def my_custom_view(request)
        # ...  your view code
        data = {
            'msg': render_to_string('messages.html', {}, RequestContext(request)),
        }
        return render_to_json(request, data)
    

    Then, in my jQuery $.post(...) callback function, I check to see if the response object has a msg attribute, and then insert the contents of response.msg into the DOM where I want it needs to be, with jQuery transitions if desired. My base.html template contains the <ul> container for the messages:

    <ul id="popup-messages-content">
        {% include 'messages.html' %}
    </ul>
    

    Note that the above includes the messages.html for the case when you want to display messages on an actual page load (non-AJAX request) – it is blank if there are no messages, but the <ul> is still available to push AJAX-received messages into.

    The last piece is the Javascript function (requires jQuery) I use in any $.post(...) callbacks to show the messages:

    function showPopupMessage(content) {
        var elMessages = $('#popup-messages-content');
        if (elMessages.length && content) {
            elMessages.html(content);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the jquery ajax plugin to submit a form. $('#profile-form').ajaxForm({ success:function(response, statusText,
I'm using the JQuery plugin AjaxForm (http://jquery.malsup.com/form/) to submit the contents of a form
I'm using the jQuery plugin ajaxForm to submit a file upload form via AJAX.
I have file upload using jquery form plugin as $(function() { $(#Form).ajaxForm({ iframe: true,
Hei there, I started using ajaxForm plugin, having the form statement like this: <form
i'm trying to submit my Ajax form using jQuery. However calling the submit() function
Hi I have managed to get my form to submit without reloading, using this
I'm using the jQuery form plugin to call a function before submitting the form.
I'm using the jQuery Form plugin to do an 'ajax' submit of my form,
i'm using ajax form jquery plugin to submit a form (in a dialog) via

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.