I am wondering if there is a (universal?) way to detect if something
is loading through AJAX in here. We have a custom error page for when
the user encounters an error but we want to have something different
display when the erroring page is loaded in AJAX.
We already had the idea of putting an "&isJS=1" flag in the JS post/
gets but figured that would be too hard to implement in already
existing code and to have everyone remember to put that in when
building stuff in the future - does anyone know a good way to
accomplish this across the board?
You can use ‘getHTTPRequestData()’ and look for the ‘XMLHttpRequest’ header. All the populate ajax libraries (including my prefered jQuery) will append that header.
var httpData = getHTTPRequestData();
var isAjax = structKeyExists(httpData.headers, ‘X-Requested-With’) && httpData.headers[‘X-Requested-With’] == ‘XMLHttpRequest’;