【问题标题】:How to get a 'select-option' area updated automatically with the values from the database..?如何使用数据库中的值自动更新“选择选项”区域..?
【发布时间】:2013-08-13 07:46:01
【问题描述】:

我想要一个“选择选项”,其中选项值将自动更新。我的意思是
我希望将数据库中的一些特定值放在选择选项区域中 在数据库中更新,就像用户在数据库中注册时一样,我希望他/她的注册号同时在“选项选择”区域中更新。我该怎么做。我在 java/jsp/servlet 中编码。

【问题讨论】:

  • 你走了多远?
  • 我一直在寻找解决方案,但没有找到。我也发现很难准确地描述我的问题。如果我找不到解决方案,我可能会选择其他选项。

标签: jsp servlets


【解决方案1】:

我不知道我的问题是否正确,但关键是使用 js-->java-->js

@RequestMapping("/url/loadData")
@ResponseBody
 public String loadData()
            throws Exception {
        JSONSerializer s = new JSONSerializer();
        return s.serialize(classService.getData());   //method to find the parsing of data from db
    }

在js中调用映射

 function loadDbData() {
    $.ajaxUtility({
        url : '/url/loadData.htm',
        showErrorPrompt : true,
        showInfoPrompt : false,
        success : function(data, xhr, s) {
            dataFromDB = data;
            $(dataFromDB).each(function(index, value){

                $("#myDropdownbox").empty();
                $("#myDropdownbox").append(generateEachData(value));

            });

        }
    });
 }

function generateEachData(dataItems){
    html = '<option>'+dataItems+'</option>';
    return html;
}

当您想要更新或调用 db 中的数据时,只需在事件上调用 loadDbData()。 希望它会有所帮助:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-30
    • 1970-01-01
    • 2016-09-19
    • 2017-07-19
    • 2012-12-10
    • 2018-12-11
    相关资源
    最近更新 更多