I have following ajax query that gets generated from my template.
This is done after user has logged into the system. One thing I have
noticed is very first GET request always prompts a dialog box that
asks users to login with username and password. I have done
console.log and csrf_token is non-null when this dialog is shown. Does
anybody have idea why this happens on all subsequnt reloads of this
page I never get prompted to enter username & password.
$.ajax({
type: "GET",
withCredentials: true,
async: false,
url: "/api/v1/myurl/",
data: {
csrfmiddlewaretoken: '{{ csrf_token }}'
},
success: function( json) {
});
It was suggested to me that I should follow this and make sure that
csrf token is present in the header.
https://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ajax
I have made sure that in my javascript I have recommended code that
set the Requestheader but that doesn't help!
Can anyone help me with this?
-Subodh