jQUery_review之jQuery的终极ajax方法$.ajax()
前端页面的代码:
<%@ 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(){ $.ajax({ url:"test", type:"get", timeout:2000, data:{name:"czz",address:"address"}, dataType:'html', beforeSend:function(){alert('beforeSend');}, complete:function(){alert('complete');}, success:function(data,status){alert(data);}, error:function(){alert('error');}, global:false }); }); }); </script> </head> <body> <div id="showText"><span>He who hesitates is lost.</span></div> <input type="button" id="getContent" value="getAjax"> </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.getWriter().print(sb.toString()); }
其实jQuery最好的资料就是官方的文档,上面有所有详细的内容,周末愉快!
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。