问题
I have an text box which is autocomplete enabled from DB.I'm using Javascript to enable autocomplete functionality.
$("#loanApplicationNo").autocomplete("<s:url action="/suggestByLoanApplicationNo"/>",{maxItemsToShow : 5});
When I type some thing on the textbox, choices will appear in the text box and when I choose/select a particular result, I want a seperate action to be called.
<s:textfield name="loan.applicationNo" id="loanApplicationNo" theme="simple" />
<a id="depositSearch" class="example6 cboxElement" href="/casba-pa-war/ln/3106.action?from=7005" title="Customer Accounts Search" style="padding-left: 25px; padding-bottom: 25px; text-decoration: none; font-size: 12px;">
<img alt="search" src="../images/search.jpeg" border="0px"/>
</a>
How can I achieve this.I tried a lot but failed to fire a seperate action for selection.
回答1:
The url
tag is used to build and render the action ready URL from the action name and/or namespace attributes, and also could be parametrized. The action
attribute should contain the valid action name not the path.
$("#loanApplicationNo").autocomplete({
source: function(request, response) {
$.getJSON('<s:url action="suggestByLoanApplicationNo"/>', {
term: extractLast(request.term)
}, response);
}
});
The action should return json
result that is available if you configure the package to extend the json-default
.
来源:https://stackoverflow.com/questions/22195394/how-to-give-seperate-action-for-selectionsselect-event-in-struts2-used-in-an