gsr
02/21/2024, 12:03 AMjc
02/21/2024, 5:20 AMXMLHttpRequest by looking for this value in the ["X-Requested-With"] header. If you are using fetch in the JS side, then this useful header is not included but you can add headers to your fetch calls. I tend to add it and just add the word fetch. Here is a function I have that I use in many places. Place it in your Application.cfc and then you can use it wherever you want in it or within your views.
But I too recommend that you do not try to inject stuff @ onRequestEnd() especially if you are not inspecting the output and then re-injecting before your body close tag to retain proper structure.
public boolean function isAjax(){
var req = getHttpRequestData().headers;
return structKeyExists(req,"X-Requested-With") && listFindNoCase("fetch,XMLHttpRequest",req["X-Requested-With"]) ? true : false;
}aliaspooryorik
X-Requested-With is not a standard HTTP header but quite a few Javascript libraries do set it for you (like jQuery) so may already be there.gsr
02/21/2024, 11:28 AMjc
02/21/2024, 2:09 PMgsr
02/21/2024, 2:20 PMjc
02/21/2024, 2:24 PMgsr
02/21/2024, 2:26 PM