Note that there are some explanatory texts on larger screens.

plurals
  1. POAjax call failing in Django
    primarykey
    data
    text
    <p>I have the following ajax call to update a particular field of a model</p> <pre><code>$("#updateLink").click(function(){ var dec_text = $('#desc_text').val(); $.ajax({ type: "POST", url:"/users/update_desc/", data: { 'val': dec_text, }, success: function(){ $(".display, .edit").toggle(); $("#descText").html(dec_text); }, error: function(){ alert("Error"); }, }); return false; }); </code></pre> <p>and my view is this </p> <pre><code>@csrf_exempt def update_desc(request): if request.is_ajax(): if request.method == 'POST': desc_text = request.POST.get('val', False) if desc_text: profile = user.profile profile.desc = desc_text profile.save() return_message = "Sent mail" return HttpResponse(return_message,mimetype='application/javascript') </code></pre> <p>I am constantly getting an error message and I don't know how to solve this. I even used the <code>csrf_exempt</code> decorator to workaround if the problem was caused by a missing <code>csrf token</code> but still the problem persists.</p> <p>Except one <code>ajax post</code> which in my <code>base</code> template all the ajax calls are failing. Can anybody please help to understand what is happening here. I can give some more details if required.</p> <p><strong>Edit:</strong></p> <p>I have added the a <code>js</code> file containing this <a href="https://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ajax">https://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ajax</a> in my base template, so it means it is present in all my templates. And I am using django 1.3 version. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload