dojo对ajax的支持

前端之家收集整理的这篇文章主要介绍了dojo对ajax的支持前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

今天贴一个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>

猜你在找的Dojo相关文章