Vanilla JS ajax post not triggering Tracy bar
- tpr
- Member | 55
Hi,
I spent some time figuring out why Tracy ajax bar doesn't show up when using pure vanilla JavaScript instead jQuery when doing an ajax post.
I've set ‘X-Requested-With’ to ‘XMLHttpRequest’ (otherwise the entire
post is not working)
The response does have ‘X-Tracy-Ajax’ so Tracy surely detects that this is
an ajax call, but the bar is still not showing. However, if I substitute the js
with jQuery ajax, it works fine.
Any clue on this? I can provide further details if you wish. Note that I'm using the standalone Tracy but I guess this doesn't make a difference.
- Jan Tvrdík
- Nette guru | 2595
I think you need to call either xhr.getResponseHeader()
or
xhr.getAllResponseHeaders()
- tpr
- Member | 55
It seems that the ajax debug bar isn't showing up if I set the header to this:
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
Setting it to ‘application/json’ or simply omitting makes the bar
appear.
I'm submitting a form so obviously json won't work.
Last edited by tpr (2016-07-18 15:46)
- adrianbj
- Member | 31
Everything is working great for me now also! Looks like it was this
change:
https://github.com/…0b07c7795831
that made the difference. Credit goes to @tpr for figuring this out.
Last edited by adrianbj (2016-07-30 16:36)