HTTP_X_REQUESTED_WITH not set in ajax call with jquery

人走茶凉 提交于 2019-12-05 14:59:52

I'm gonna answer my own question. The problem was with the jquery .ajax() method. I don't know why but this method does not set the X-Requested-With to XMLHttpRequest, which is needed by Django to check if the request is an ajax request. I even tried to add the header with the ways specified in my previous comment (headers: { 'X-Requested-With': 'XMLHttpRequest' } and beforeSend: function(xhr) { xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); },). Instead, I use the .get() method that I guess that by default set this header and it works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!