88323

How to call struts action from plain javascript file

Question:

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.

Answer1:

You can use <a href="https://api.jquery.com/jQuery.ajax/" rel="nofollow">jQuery ajax</a> 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.

Recommend

  • How to Mantain Session with AngularJS Website from Native App?
  • .Net MVC Core Policy based authorization with JWT
  • Memory Error When Parsing Large File - Python
  • How do I remove line feed characters when selecting data from SQL Server?
  • What is the diff. between default.properties and project.properties?
  • Making query to find nearest multiple(Lat,Long) from the single(Lat,Long)
  • How to smoothly connect two signals in matlab [closed]
  • Eric5: The OK button of 'new project' dialog is disable
  • How to convert days into months using datetime in Python3?
  • Protractor Page objects - TypeError: Object # has no method 'methodName'
  • How can I filter an array of dictionaries in 'updateSearchResultsForSearchController' to s
  • Pandas time series data Index from a string to float [duplicate]
  • AWS RDS Parameter Group not changing MySQL encoding
  • readmore button or show/hide for php
  • Copy and paste data from multiple workbooks to a worksheet in another Workbook
  • What is the difference between dynamically creating a script tag and statically embed a script tag?
  • Add font awesome icon to custom add to cart button in Woocommerce 3
  • How to define something in JavaScript [closed]
  • Runtime complexity of getting the length of a string in different representations
  • How to write seo friendly url's using htaccess?
  • Create an average of multiple excel chart without the data source
  • Django, uWSGI & nginx: Process dies for “no reason”
  • using maven pom while creating jar:test-jar some times it says JAR will be empty - no content was ma
  • Neo4j…how to get a visual representation of my data?
  • JavaScript Regex to Match Boundaries of Words with diacritics
  • how to run ejabberd with Erlang on Heroku?
  • How to use Streams api peek() function and make it work?
  • Android: Unable to detect vertical plane
  • reshape/remould data frame to create normalized bar chart and pie chart
  • `$http:badreq Bad Request Configuration` - from angular post method, what is wrong here?
  • Bind selectedDates Aggregation for Calendar
  • Debug `Unexpected end of JSON input Error` on content script
  • Bad automatic Triangulation with Mayavi for coloring a surface known only by its corner
  • How to get rgb from transparent pixel in js
  • ssh remote server login script
  • Computing the discrete fourier transform of audio data with FFTW
  • Bitrate JWplayer
  • Using Service Component Runtime
  • Accessing Arguments, Workflow Variables from custom activities
  • How to handle a codeigniter PDF generator