今天贴一个dojo的ajax例子,发送post请求,可以作为ajax的模板,用到的时候方便。 %@ page language="java" import="java.util.*" pageEncoding="utf-8"%%String path = request.getContextPath();String basePath = request.g
今天贴一个dojo的ajax例子,发送post请求,可以作为ajax的模板,用到的时候方便。
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'ajaxTest.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <link rel="stylesheet" href="resources/dojo/dijit/themes/claro/claro.css"> <script type="text/javascript" src="resources/dojo/dojo/dojo.js" djConfig="parseOnLoad:true"></script> <script type="text/javascript"> require([ "dojo/parser", "dojo/_base/xhr", "dijit/dijit", "dojo/on", "dijit/form/Form", "dijit/form/TextBox", "dojo/domReady!" ], function(parser, xhr, dijit, on){ on(dojo.byId("submit"), "click", function(){ xhr.post({ url:"ajaxTest", form : "myForm", handleAs : "json", load : function(data) { console.log(data); } }); }); }); </script> </head> <body> <div method="post" data-dojo-id="myForm" data-dojo-type="dijit/form/Form" id="myForm"> 用户名:<input type="text" id="username" data-dojo-type="dijit/form/TextBox" name="username"><br/> 密 码:<input type="password" id="passwd" data-dojo-type="dijit/form/TextBox" name="passwd"><br/> <input type="button" value="提交" id="submit"> </div> </body> </html>