> "Either way I cannot get the ajax call to succeed in triggering the django 
> backend at all"
>
 
By "django backend" I simply mean the persistent_messages/views.py, which 
should be referenced when the ajax url calls /messages/marked_read/X (as 
defined in persistent_messages/urls.py. Again a reminder that accessing the 
same link manually succeeds in calling the correct methods defined in 
persistent_messages/views.py

On Monday, July 8, 2013 2:30:56 AM UTC-5, [email protected] wrote:
>
> I added the getcookie call to grab csrftoken (ref from the link you 
> provided), 
> but the farthest I can get is by setting ajax async:false which causes the 
> status reported by chrome developer tools (for call /messages/marked_read/X 
> ) to be PENDING.
> Without async:false, it just goes to CANCELLED.
>
> Either way I cannot get the ajax call to succeed in triggering the django 
> backend at all.
> Nor do the server error logs report anything going wrong.
>
>
> On Friday, July 5, 2013 12:03:55 AM UTC-5, Peith wrote:
>>
>> If that's an AJAX POST request, then it may be because you are not 
>> passing the CSRF token in the header. Add this code before doing the AJAX 
>> call:
>>
>> function csrfSafeMethod(method) {
>>     // these HTTP methods do not require CSRF protection
>>     return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));}$.ajaxSetup({
>>     crossDomain: false, // obviates need for sameOrigin test
>>     beforeSend: function(xhr, settings) {
>>         if (!csrfSafeMethod(settings.type)) {
>>             xhr.setRequestHeader("X-CSRFToken", csrftoken);
>>         }
>>     }});
>>
>> See here: https://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ajax
>>
>>
>>
>>
>> On Fri, Jul 5, 2013 at 10:03 AM, <[email protected]> wrote:
>>
>>> So I have django 1.5.1 installed,
>>> have persistent messages installed, and have messages displaying in a 
>>> list
>>> via the template reference {% include 
>>> "persistent_messages/message/includes/messages.jquery.html" %}
>>>
>>> The following javascript click trigger is bound to an anchor tag within 
>>> the list:
>>>
>>> $(closeSelector).click(function(event) {
>>>         event.preventDefault();
>>>         $.ajax({
>>>                 url: "//url.com/"+$(this).attr('href')
>>>         })
>>>         if ($(messageSelector).length <= 2) {
>>>             $(closeAllSelector).messageClose();
>>>         }
>>>
>>>         $(this).closest(messageSelector).messageClose();
>>>     });
>>>
>>> The link being referenced is https://url.com/messages/mark_read/583/ 
>>> If I access that same link manually in the address bar, the appropriate 
>>> call in the backend
>>> gets executed and the message is marked read. The ajax equivalent never 
>>> seems to respond.
>>> I added logging to the persistent messages view and confirmed the ajax 
>>> call is never
>>> calling mark_read() method.
>>>
>>> Chrome dev tools indicates that the ajax call is "pending" and never 
>>> changes from this state.
>>>
>>> Any suggestions or ideas on what may be causing this?
>>>
>>> NOTE: I prepend the "//url.com" to avoid getting 'insecure content' 
>>> warnings, since this ajax code is being executed
>>> from a https page. This change did not seem to affect the bug in any 
>>> way, since the response is the same.
>>>
>>> Thanks in advance 
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to [email protected].
>>> To post to this group, send email to [email protected].
>>> Visit this group at http://groups.google.com/group/django-users.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>  
>>>  
>>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to