This may be basic, but I spent two days reading countless tutorials, and I still can't get it to work. To simplify, I tried to complete the main task just to see how it works. I want to send an ajax request for my donated look. I see that it succeeds, but I expected that my template will also be updated to "TRUE", but it will remain "FALSE". Any help or suggestions I appreciate.
my jquery ...
$.ajax({ type: "POST", url:"/donate/", data: { 'test': 'success', }, success: function(){ alert('test') }, error: function(){ alert("Error"); });
it's my opinion...
def donate(request): if request.is_ajax(): test = "TRUE" if request.method == 'POST': form = DonateForm(request.POST) if form.is_valid(): form.save() else: form = DonateForm() test = "FALSE" return render_to_response('donate_form.html', {'form':form,'test':test}, context_instance=RequestContext(request))
My template includes this ...
<h1>{{ test }}</h1>
Update / Solution
As mentioned in the comments on this, I did nothing with the returned data. I updated my success request to the next and it worked
$.ajax({ type: "POST", url:"/donate/", data: { 'zip': zip, }, success: function(data){ results = $(data).find('#results').html() $("#id_date").replaceWith("<span>" + results + "</span >"); }, error: function(){ alert("Error"); },
Austin
source share