2

This query is related to struts 1.3.

Let's say I have one action called 'getName.do' which is mapped to 'GetName.java' action class. In the dmexecute method of this action class, I am setting one result say String result = Hello;.

My query is how I can call this struts action (getName.do?parameter=value) from one of my javascript files.

Essentially, I want the value of result, which is Hello, to be present in my javascript file through this getName.do?parameter=value call. How I can make this call in my javascript file.

Any help will be highly appreciated.

Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
Deepak Agrawal
  • 290
  • 1
  • 5
  • 14

1 Answers1

1

You can use jQuery ajax for this purpose.

Importing jquery file:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

Calling action through jquery ajax:

<script type="text/javascript">
$.ajax({
    url : "getName.do?parameter=value",
    type : "POST",
    success : function(data) {
        // You'll get your response here
        alert(data);
    }
});
</script>

Hope this will help.

Vinoth Krishnan
  • 2,925
  • 6
  • 29
  • 34
  • Hi @Vinoth : Actually, I need to make the above ajax call from one of my javascript files. Can you please suggest how to include jquery.min.js in my javascript file. ? – Deepak Agrawal Dec 29 '16 at 05:01
  • You can include the path in HTML and make sure this file getting loaded before the your javascript file. Like ` ` – Vinoth Krishnan Dec 29 '16 at 09:48