I have a situation where I am trying to trigger an Ajax javascript function from my jsp file, with the intention of loading a servlet for further processing. The issue I am facing is that even though I am able to pass values from the jsp to the ajax function successfully, the servlet is not being called as expected. Despite conducting thorough research online, I have been unable to identify the missing piece of the puzzle.
Below is a snippet of my jsp code where I call the ajax javascript function:
<display:column title="Merge Print"><a href="#" onClick="printMerge('arg1', 'arg2')">Click Here</a></display:column>
In a separate ajax.js file, here is the code for my printMerge function:
function printMerge(arg1, arg2) {
alert('In printMerge '+arg1, arg2);
new Ajax.Request('servlet/PrintMerge', {
method: 'post',
parameters: { arg1: arg1.value, arg2: arg2.value },
onSuccess: function(transport) {
var response = transport.responseText || "no response text";
if(response =='success') {
alert('RESPONSE: SUCCESS');
reloadPage();
} else {
alert('RESPONSE: ERROR');
},
onFailure: function() { alert('FAILURE'); }
});
}
While the initial alert displays the arguments correctly, indicating that the jsp is effectively calling the function and passing the parameters, the process seems to halt there without progressing to the 'PrintMerge' servlet for further actions.
This is how the PrintMerge servlet looks like:
<servlet>
<servlet-name>PrintMerge</servlet-name>
<servlet-class>com.servlet.PrintMerge</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>PrintMerge</servlet-name>
<url-pattern>/servlet/PrintMerge</url-pattern>
</servlet-mapping>
Although similar configurations work for other scenarios, I believe there might be a crucial step that I am overlooking since the ajax function fails to reach the servlet. Your insights or suggestions on this matter would be greatly appreciated. Thank you for your help in advance.