Paul R
Paul R

Reputation: 2797

Django request.is_ajax returns False when using XMLHttpRequest

I'm sending cross-domain ajax request and on another end request.is_ajax() gives False

var text = getSelectedText();
  text = 'text';
  if (text){
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            console.log(this.responseText)
        }
    };

    xhttp.open("GET", "http://example.com/text=" + encodeURIComponent(text), true);
    xhttp.send();}

Upvotes: 2

Views: 802

Answers (1)

Udi
Udi

Reputation: 30532

You will have do add it manually (as jQuery and other libraries does):

xhttp.setRequestHeader('X-Requested-With', 'XMLHttpRequest');

Upvotes: 7

Related Questions