How to call struts action from plain javascript file

半腔热情 提交于 2019-12-11 06:07:15

问题


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.


回答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.



来源:https://stackoverflow.com/questions/41354951/how-to-call-struts-action-from-plain-javascript-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!