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

后端 未结 6 1452
小鲜肉
小鲜肉 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条回答
  •  醉酒成梦
    2020-12-14 03:55

    The reason I got this was because I was taking an element with my AJAX event handler attached, cloning it and then adding the new element to my document. For some reason this meant that the event attached to the new element would not treat it as a normal ajax request (Accept:text/html instead of application/json, no X-Requested-With etc.)

    To fix this all I did was change the event to jQuery's new equivalent of live() (unsure what they call it now). So from:

    $('a.basket-add').click(function() { /* etc */ });
    

    To:

    $(document).on('click', '.basket-add', function() { /* etc */ });
    

提交回复
热议问题