国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > AJAX > 正文

通過Ajax請求動態(tài)填充頁面數(shù)據(jù)的實(shí)例

2024-09-01 08:26:46
字體:
供稿:網(wǎng)友

你可能得預(yù)先了解

實(shí)現(xiàn)功能:點(diǎn)擊頁面上的按鈕實(shí)現(xiàn)動態(tài)追加數(shù)據(jù)

實(shí)現(xiàn)原理:點(diǎn)擊頁面按鈕,通過Ajax提交請求到后臺,后臺接收請求后進(jìn)行數(shù)據(jù)庫操作,然后返回?cái)?shù)據(jù)到前臺并進(jìn)行頁面渲染

動態(tài)加載更多數(shù)據(jù)

代碼實(shí)現(xiàn)

//1.頁面布局<div style="padding: 0 0 20px 0;"> <input type="hidden" class="tip" value="1"> <input style="background:#01affe;color: #FFF;cursor: pointer;    text-align:center;height:30px;vertical-align: middle;padding:0 5px;    type="button" name="more" id="more" value="加載更多" onclick="moreData();"/></div>//2.js代碼function moreData(){  var ptip = $('.tip').val();  var jstr = {pageNo:ptip};  $.ajax({   url: '${rc.getContextPath()}/publicity/more.do',//url以具體為實(shí)現(xiàn)   type: 'POST',   dataType: 'html',   data:jstr,   timeout: 5000,   cache: false,   beforeSend: LoadFunction, //加載執(zhí)行方法   error: erryFunction, //錯(cuò)誤執(zhí)行方法   success: succFunction //成功執(zhí)行方法  })  function LoadFunction() {   $("#more").val('加載中...');  }  function erryFunction() {  alert("獲取數(shù)據(jù)錯(cuò)誤,請重試!");  $("#more").val('加載更多');  }  function succFunction(data) {  if(data!=null && data!=""){   $('.tip').val(++ptip);   $("#more").val('加載更多');   $('.mainContent').append(data);  }else{   $("#more").val('無更多數(shù)據(jù)');   $("#more").attr('disabled',true);  } }//3.后臺代碼//3.1 java代碼實(shí)現(xiàn)import java.util.List;import javax.servlet.http.HttpServletRequest;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.ui.ModelMap;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import com.appmoudle.base.Consts;import com.appmoudle.model.ssdj.Publicity;import com.appmoudle.service.PublicityService;@Controller@RequestMapping("/publicity")public class MoreData { private String ftlURL = ".../publicity/MoreData.ftl"; @Autowired private PublicityService publicityService; @RequestMapping(value="more",method=RequestMethod.POST) public String getMoreData(HttpServletRequest request,ModelMap map){  Integer start = 0;  String pageNo = request.getParameter("pageNo");  if(pageNo!=null){   start = Integer.parseInt(pageNo) * 20;  }  List<Publicity> dataList = publicityService.findList(start, Consts.PAGE_SIZE, null, "1", null, null);  map.put("index_number", start);  map.put("dataList", dataList);  return ftlURL; }}//3.2 模板頁面//(MoreData.ftl)<#if dataList??> <#list dataList as dataItem>  <tr>   <td class='f-blue'>${dataItem_index+1+index_number}</td>   <td>    <#if dataItem.comp_name?length > 12>     ${dataItem.comp_name?substring(0,12)}..    <#else>     ${dataItem.comp_name}    </#if>   </td>   <td>${dataItem.license_number}</td>   <td>    <#if dataItem.license_name?length > 10>     ${dataItem.license_name?substring(0,10)}..    <#else>     ${dataItem.license_name}    </#if>   </td>     <td>    <#if dataItem.validaty_start?has_content>     ${dataItem.validaty_start?date}    </#if>   </td>    <td>    <#if dataItem.validaty_end?has_content>     ${dataItem.validaty_end?date}    </#if>   </td>    <td>    <#if dataItem.license_content?length > 20>     ${dataItem.license_content?substring(0,20)}..    <#else>     ${dataItem.license_content}    </#if>    </td>  </tr> </#list></#if>            
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 城固县| 镇平县| 上蔡县| 平罗县| 陆丰市| 哈巴河县| 汝南县| 扶绥县| 高碑店市| 武威市| 凤城市| 苏尼特左旗| 紫金县| 泗洪县| 灵宝市| 银川市| 南靖县| 葵青区| 扬中市| 鹤峰县| 高邮市| 弋阳县| 庆阳市| 开封县| 玉树县| 山丹县| 黔江区| 陇西县| 黑水县| 达孜县| 田林县| 当雄县| 三门峡市| 瑞昌市| 漳平市| 防城港市| 汉中市| 贺州市| 石门县| 青浦区| 漾濞|