I am using JQuery-Ajax, and History.js for my web app, is there anyway I can identify if the request came from an AJAX request or just normal request? What I aim to do is something like this
<%if(isRequestAjax()){%>
<jsp:include page="/views/header.jsp" />
}
<%}%>
<div id ="profilePage>
<!-- user profile will be loaded here !-->
</div>
I am also using Struts2 as may MVC framework
An AJAX request is a request made by an AJAX application. Typically, it is an HTTP request made by (browser-resident) Javascript that uses XML to encode the request data and/or response data.
To create ajax example, you need to use any server-side language e.g. Servlet, JSP, PHP, ASP.Net etc.
How AJAX Calls Work. AJAX uses both a browser built-in XMLHttpRequest object to get data from the web server and JavaScript and HTML DOM to display that content to the user. Despite the name “AJAX” these calls can also transport data as plain text or JSON instead of XML.
You have to check for a request header X-Requested-With
it will be XMLHttpRequest
if ("XMLHttpRequest".equals(req.getHeader("X-Requested-With")) ){
// include other file
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With