今天贴一个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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。