Ajax非同步載入

來源:互聯網
上載者:User

標籤:ogg   servlet   efi   adc   .ajax   for   loaddata   dialog   反選   

         //第一步 使用@Expose尋找         //實體類的屬性名稱不一定與資料庫列名相同,但是類型一定要匹配    //當使用gson進行生產json字串時,可以通過判斷是否有該註解產生字  符串內容    //如由註解就添加到字串中,沒有的就不添加到json字串中    //說明:需要使用如下方式執行個體化gson對象:new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();    @Expose    private int id;    @Expose    private String cname;       //使用集合儲存多條商品資訊--list        private  List<Goods> goods;//第二步 編寫一個Action@RequestMapping("/listcategory")    public void listCategoryForAjax(HttpServletResponse response) throws IOException {        List<Category> list = categoryService.findAll();        // 通過Expose註解排除某些欄位資訊,即有些資料不添加到Json字串中        String s = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().toJson(list);        logger.info(list.size() + " :::::::::  " + s);        // 把資料返回給瀏覽器--返回給jquery ui        response.setContentType("text/html; charset=UTF-8");        response.getWriter().write(s);        response.getWriter().flush();    }//第三步 添加標籤<select id="category" name="category" class="easyui-combobox" data-options="valueField:‘id‘, textField:‘cname‘, panelHeight:‘auto‘, width:‘80‘">//第四步 編寫javaScript代碼var url;//開啟新增視窗function newGoods(){    $(‘#dlg‘).dialog(‘open‘).dialog(‘setTitle‘,‘新增商品‘);    //$(‘#fm‘).form(‘clear‘);    $(‘#fm‘).form(‘reset‘);    url = ‘goods/saveGoodsForAjax.do‘;        //開啟新增視窗,載入分類資訊    loadCategory();    }function loadCategory(){                var dat = $(‘#dg‘).datagrid(‘getSelected‘);     $.ajax({url:"goods/listcategory.do",dataType:‘json‘,type:‘post‘,success:function(data){                //把查詢的資料填充到下拉式清單中        $("#category").combobox("loadData", data);        //修改選擇的項        if(dat){            //修改要反選預設值--根據value進行選擇          $(‘#category‘).combobox(‘select‘, dat.category);        }else{            //新增取第一個為預設值--根據value進行選擇             $(‘#category‘).combobox(‘select‘, data[0].id);        }    }});}

 

Ajax非同步載入

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.