亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

淺談ajax在jquery中的請(qǐng)求和servlet中的響應(yīng)

 更新時(shí)間:2018年01月22日 15:11:32   作者:星空下的那個(gè)人影  
下面小編就為大家分享一篇淺談ajax在jquery中的請(qǐng)求和servlet中的響應(yīng),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

在jsp中,首先,你需要導(dǎo)入jquery的架包:

獲取可返回站點(diǎn)的根路徑:

<% 
  String path = request.getContextPath(); 
%> 

在jquery中寫ajax請(qǐng)求:

<script type="text/javascript">
     $(function(){
        $(".B").click(function(){
        $.ajax({
            type: "GET",
                     //對(duì)應(yīng)servlet中的方法
            url: "<%=path%>" + "/queryEvaluateByuserId.do",
                     //返回是json數(shù)據(jù)
            dataType: "json",
            async:false,
           data:{
            },
            success: function(data){
              str = "";
               if(data != null){
                               //循環(huán)表單列表
                 for (var i in data)
                  {
                     var num = parseInt(i) + 1 ;                         
                    str +="<tr><td>" + num + "</td><td>" 
                    + data[i]['name'] + "</td><td>"
                    + data[i]['price'] + "元</td>" 
                    + "</tr>";
                  }
                 $(".trtd4").after(str);
               }else{
                 
               }
               
            },
            error: function(data){
            }
          }) 
      });
     }
</script>

jsp部分:

<div class="tab-pane" id="B" style="text-align:center;"> 
          <div class="row marg" > 
            <table border="2 " style="width:80%;text-align:center;"> 
              <tr class="trtd4"> 
                <th>序號(hào)</th> 
                <th>業(yè)主名</th> 
                <th>金額</th> 
              </tr>              
            </table> 
          </div> 
        </div> 

在servlet中用到了阿里巴巴的快速轉(zhuǎn)換json的包c(diǎn)om.alibaba.fastjson.JSON:

private void queryEvaluateByuserId(HttpServletRequest request, HttpServletResponse response) throws SQLException, IOException, ServletException{
			HttpSession session=request.getSession();
			request.setCharacterEncoding("UTF-8");
			response.setContentType("text/html");
			response.setCharacterEncoding("UTF-8");
			Cookie[] cookies = request.getCookies();
			int ownerId = 0;
			for (int i = 0; i < cookies.length; i++) {
	      Cookie cookie = cookies[i];
	      if (cookie.getName().equals("ownerId")) {
	      	ownerId = Integer.parseInt(cookie.getValue()); 
	      }
			}
			List<Order> orderList = new ArrayList<>();
			List<Evaluate> queryEvaluateList = new ArrayList<>();
			orderList = orderServiceImpl.queryOrderList(ownerId, null, null, null, null, null);
			List<Map<String, String>> workers = new ArrayList<Map<String, String>>(); 
			for(int i = 0;i < orderList.size();i++){
				Map<String,String> order = new HashMap<String, String>();
				order.put("description", orderList.get(i).getDescription());
				order.put("name", orderList.get(i).getOwnerName());
				System.out.println(orderList.get(i).getDescription());
				order.put("type",orderList.get(i).getTypeName());
				queryEvaluateList = orderServiceImpl.queryEvaluateListByUserId(orderList.get(i).getId());
				order.put("comment", queryEvaluateList.get(0).getComment());
				List<Allocation> allocation = orderServiceImpl.queryAllocationByOrderId(orderList.get(i).getId());
				order.put("price", String.valueOf(allocation.get(0).getPrice()));
				 System.out.println(order);
				workers.add(order);
			}
            //將map鍵值對(duì)轉(zhuǎn)換成json,傳給jsp
            response.getOutputStream().write(JSON.toJSONBytes(workers));
		}

以上這篇淺談ajax在jquery中的請(qǐng)求和servlet中的響應(yīng)就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • jQuery動(dòng)態(tài)星級(jí)評(píng)分效果實(shí)現(xiàn)方法

    jQuery動(dòng)態(tài)星級(jí)評(píng)分效果實(shí)現(xiàn)方法

    這篇文章主要介紹了jQuery動(dòng)態(tài)星級(jí)評(píng)分效果實(shí)現(xiàn)方法,涉及jquery動(dòng)態(tài)操作頁(yè)面元素樣式的相關(guān)技巧,效果華麗大氣,是一款非常優(yōu)秀的特效源碼,需要的朋友可以參考下
    2015-08-08
  • jQuery 表格插件整理

    jQuery 表格插件整理

    本文搜集了大量 jQuery 表格插件,幫助 Web 設(shè)計(jì)者更好地駕御 HTML 表格,你可以對(duì)表格進(jìn)行橫向和豎向排序,設(shè)置固定表頭,對(duì)表格進(jìn)行搜索,對(duì)大表格進(jìn)行分頁(yè),對(duì)表格進(jìn)行滾動(dòng),拖放操作等等。這些插件很多都包含詳細(xì)的教程。
    2010-04-04
  • jQuery隊(duì)列操作方法實(shí)例

    jQuery隊(duì)列操作方法實(shí)例

    這篇文章主要介紹了jQuery隊(duì)列操作方法實(shí)例,總結(jié)出了一個(gè)簡(jiǎn)潔優(yōu)雅的隊(duì)列控制方法,需要的朋友可以參考下
    2014-06-06
  • JQuery ztree 異步加載實(shí)例講解

    JQuery ztree 異步加載實(shí)例講解

    這篇文章主要為大家詳細(xì)介紹了JQuery ztree異步加載實(shí)例,感興趣的小伙伴們可以參考一下
    2016-02-02
  • jQuery實(shí)現(xiàn)移動(dòng) 和 漸變特效的點(diǎn)擊事件

    jQuery實(shí)現(xiàn)移動(dòng) 和 漸變特效的點(diǎn)擊事件

    這里給大家分享的是一則使用jQuery實(shí)現(xiàn)移動(dòng)和漸變特效的點(diǎn)擊事件效果,非常簡(jiǎn)單實(shí)用,這里推薦給大家。
    2015-02-02
  • jQuery中parents()和parent()的區(qū)別分析

    jQuery中parents()和parent()的區(qū)別分析

    這篇文章主要介紹了jQuery中parents()和parent()的區(qū)別,具體分析了parents()和parent()的原理與用法區(qū)別,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2014-10-10
  • jquery入門——事件機(jī)制之事件中的冒泡現(xiàn)象示例解釋

    jquery入門——事件機(jī)制之事件中的冒泡現(xiàn)象示例解釋

    事件被觸發(fā)后被分為兩個(gè)階段,一個(gè)是捕獲(Capture),另一個(gè)是冒泡(Bubbing),但大多瀏覽器并不是都支持捕獲階段,因此事件被觸發(fā)后,往往執(zhí)行冒泡過(guò)程,感興趣的朋友可以了解下,或許對(duì)你學(xué)習(xí)事件機(jī)制有所幫助
    2013-02-02
  • jQuery ajax調(diào)用WCF服務(wù)實(shí)例

    jQuery ajax調(diào)用WCF服務(wù)實(shí)例

    這篇文章主要介紹了jQuery ajax調(diào)用WCF服務(wù)實(shí)例,包含服務(wù)器端和客戶端的實(shí)現(xiàn)代碼,需要的朋友可以參考下
    2014-07-07
  • 使用PHP+JQuery+Ajax分頁(yè)的實(shí)現(xiàn)

    使用PHP+JQuery+Ajax分頁(yè)的實(shí)現(xiàn)

    本篇文章小編將為大家介紹,使用PHP+JQuery+Ajax分頁(yè)的實(shí)現(xiàn)。需要的朋友參考下
    2013-04-04
  • jQuery實(shí)現(xiàn)鼠標(biāo)單擊網(wǎng)頁(yè)文字后在文本框顯示的方法

    jQuery實(shí)現(xiàn)鼠標(biāo)單擊網(wǎng)頁(yè)文字后在文本框顯示的方法

    這篇文章主要介紹了jQuery實(shí)現(xiàn)鼠標(biāo)單擊網(wǎng)頁(yè)文字后在文本框顯示的方法,可實(shí)現(xiàn)鼠標(biāo)點(diǎn)擊上方文字即可在下方勾選處文本框顯示對(duì)應(yīng)文字的效果,涉及jQuery鼠標(biāo)事件及鏈?zhǔn)讲僮鞯南嚓P(guān)技巧,需要的朋友可以參考下
    2015-05-05

最新評(píng)論