首頁  >  文章  >  web前端  >  有關ajax在jquery中的請求(詳細教程)

有關ajax在jquery中的請求(詳細教程)

亚连
亚连原創
2018-06-11 10:31:041175瀏覽

下面我就為大家分享一篇淺談ajax在jquery中的請求和servlet中的回應,具有很好的參考價值,希望對大家有所幫助。

在jsp中,首先,你需要匯入jquery的架包:

# 取得可傳回網站的根路徑:

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

在jquery中寫ajax請求:

#

##jsp部分:#

序号 业主名 金额

在servlet中用到了阿里巴巴的快速轉換json的套件com.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 orderList = new ArrayList<>();
			List queryEvaluateList = new ArrayList<>();
			orderList = orderServiceImpl.queryOrderList(ownerId, null, null, null, null, null);
			List> workers = new ArrayList>(); 
			for(int i = 0;i < orderList.size();i++){
				Map order = new HashMap();
				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 = orderServiceImpl.queryAllocationByOrderId(orderList.get(i).getId());
				order.put("price", String.valueOf(allocation.get(0).getPrice()));
				 System.out.println(order);
				workers.add(order);
			}
            //将map键值对转换成json,传给jsp
            response.getOutputStream().write(JSON.toJSONBytes(workers));
		}

上面是我整理給大家的,希望未來會對大家有幫助。

相關文章:

在node.js中如何使用http模組

在微信中如何使用js喚起App?

node打包工具Pkg(詳細教學)

以上是有關ajax在jquery中的請求(詳細教程)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn