Jquery, No X-Requested-With=XMLHttpRequest in ajax request header?

后端 未结 6 1441
小鲜肉
小鲜肉 2020-12-14 03:35

SOME TIMES there is no X-Requested-With header, sometimes there is.

I checked in firebug and found that, don\'t know why.

So when I use requ

6条回答
  •  Happy的楠姐
    2020-12-14 03:52

    Provide more information. What kind of ajax requests are you making?

    If you are submitting forms which contain an input field of type file that is most likely the reason that the header is missing.

    As you can't submit a file with ajax, all the javascript frameworks use the "hidden iframe" trick internally to get the work done for you.

    Check this post with a similar problem and my answer to it.

    X-Requested-With header not set in jquery ajaxForm plugin


    Otherwise there should be no reason for such a behavior from jQuery as it always sets the header. If the issue isn't related to file-inputs please post relevant codesnippets

    from jQuery Source

    xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");

提交回复
热议问题