e p e p - 2 years ago 122
Javascript Question

AJAX call from a popup modal

Trying to call an AJAX request from a modal popup.

function exportReport(){
url : 'exportReport',
data : {
from : fromDate,
to : toDate
success : function(responseText) {


public class GenerateReportServlet extends HttpServlet {



<%@ page language="java" session="false" contentType="text/html; charset=ISO-8859-1"
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<div class="modal fade" id="myModal" role="dialog">
<button type="button" class="btn btn-primary btn-sm" data-dismiss="modal" onclick="exportReport()">Export</button>

main.jsp is inside
. This export button is in a popup modal div. Click on Export is calling,

and is HTTP Status 404. It should come like
. How that
is coming in the url.

Answer Source

You should be more specific when setting the url, else it will be appended to the current url.

Use url : '/myApp/exportReport' instead in the AJAX call.

The leading slash indicates that the url is absolute.

Omitting the leading slash makes the url relative to the current url.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download