当前位置 : 主页 > 网页制作 > Dojo >

dojo的ajax使用入门

来源:互联网 收集:自由互联 发布时间:2021-06-15
dojo 怎么样实现和server端的交互?那么它有自己的一套AJAX框架的内容 %@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "ht

dojo 怎么样实现和server端的交互?那么它有自己的一套AJAX框架的内容

 

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>dojo ajax</title>
<script type="text/javascript" src="../dojo/dojo/dojo.js" djConfig="parseOnLoad: true"></script>
<script type="text/javascript">
function init(){
	var timestamp = Date.parse(new Date());
	var json_content={name:"huangbiao",age:14,time:timestamp};
	dojo.xhrGet({
	    url: "../DojoAjax",//发送到servlet的路径
	    content:json_content,//这个参数是用来传递参数的
	    load: function(response, ioArgs){//成功响应的事件
	        //console.log("xhr get success:", response);
	        alert("xhr get success:", response);
	   		return response; 
	    },
	    sync:true,//默认是false
	    error: function(response, ioArgs){//失败响应的
	        //console.log("xhr get failed:", response);
	        alert("xhr get failed:", response);
	        return response; 
	    }
	});	
}
//dojo.addOnLoad(init);
</script>
</head>
<body>
<form action="../DojoAjax">
<input type="submit" value="submit">
</form>
<button onclick="init();">ajax</button>
</body>
</html>

 

server端的代码

package hb.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class DojoAjax extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("do get");
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("do post");
	}

}
网友评论