<div class="grid--cell fl1 lh-lg">
<div class="grid--cell fl1 lh-lg">
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, <a href="/help/reopen-questions">visit the help center</a>.
</div>
</div>
</div>
<div class="grid--cell mb0 mt8">Closed <span title="2013-01-13 06:54:53Z" class="relativetime">7 years ago</span>.</div>
</div>
</aside>
I want to return two messages from a django view. For example, after I created some object (message:"object was created") and after I create related object("related object was created"). I want to display these messages on current webpage. I think I need to use jQuery and Ajax post request (Ajax request + return of view, which creates object from request) and show div's after request is completed, what do you think about this?
</div>
To return a message via ajax, use alert
. I would do something like this:
def view(request):
if request.is_ajax():
//whatever you need to do
else:
//regular POST request
jquery:
$(document).ready( function() {
$('div#ajax-div').click(function(){
$.ajax({
type: "POST",
url:"/ajax-url/",
success: function(data){alert('Object was created!');}
error: function(){alert("Error");}
});
}
template:
<div id='ajax-div'>
<a href='{% url ajax-url %}'>Click here for Message</a>
</div>
url:
url(r'^ajax-url/$', 'views.view', name='ajax_url'),