jQuery_review之使用$.getScript()以及$.getJSON来与服务端进行异步信息交互
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <script type="text/javascript" src="jquery-1.8.3.js"></script> <script type="text/javascript"> $(function(){ $("#getContent").click(function(){ $.getScript("czz.js",function(){ alertHtml($("#showText")); }) }); $("#getJson").click(function(){ $.getJSON("test?name=czz&address=dszy",function(data){ var str = data['name']+" "+data['address']; $("#showText").empty().text(str); }); }); }); </script> </head> <body> <div id="showText"><span>He who hesitates is lost.</span></div> <input type="button" id="getContent" value="getAjax"> <input type="button" id="getJson" value="getJson"> </body> </html>
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String name = req.getParameter("name"); String address = req.getParameter("address"); StringBuffer sb = new StringBuffer(""); sb.append("{\"name\":\"") .append(name) .append("_czz\",\"address\":\"") .append(address) .append("_czz\"}"); resp.setContentType("html/JSON;charset=utf-8"); resp.getWriter().print(sb.toString()); }
function alertHtml(e){ alert(e.html()); }
jQuery_review之使用$.getScript()以及$.getJSON来与服务端进行异步信息交互,古老的榕树,5-wow.com
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。