Struts2 jQuery plugin + How Do call ajax from javascript for tag select

强颜欢笑 提交于 2019-12-11 18:21:32

问题


The next code works good..

           <s:url id="remoteurl" action="jsonsample"/> 
            <sj:select 
                href="%{remoteurl}" 
                id="language" 
                onChangeTopics="reloadsecondlist" 
                name="language" 
                list="languageObjList" 
                listKey="myKey" 
                listValue="myValue" 
                emptyOption="true" 
                headerKey="-1" 
                headerValue="Please Select a Language"
                />

but: these code load with <s:url id="remoteurl" action="jsonsample"/> as soon load the page... I want execute the action from javascript like this:

<div id="result" style="width: 100px; height: 100px; background-color: green;">Click me!</div>

<script type="text/javascript">
            $(document).ready(function() {
                $("#result").click(function() {

Here ... How execute the action "jsonsample"? and refresh in the select "language"
                });
            });
        </script>

回答1:


There is reloadTopics attribute in <sj:select> tag which takes a comma delimited list of topics that will cause it to reload. Add it to your <sj:select> tag and publish event using publish function.

<sj:select ... reloadTopics="reloadSelect"/>

<script type="text/javascript">
  $(document).ready(function() {
    $("#result").click(function() {
      $.publish("reloadSelect");
    });
  });
</script>


来源:https://stackoverflow.com/questions/21266513/struts2-jquery-plugin-how-do-call-ajax-from-javascript-for-tag-select

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