Struts2 jQuery plugin + How Do call ajax from java

2019-09-08 16:31发布

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条回答
乱世女痞
2楼-- · 2019-09-08 17:07

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>
查看更多
登录 后发表回答