关闭

dojo的ajax使用入门

204人阅读 评论(0) 收藏 举报

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");
	}

}

 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:309647次
    • 积分:8708
    • 等级:
    • 排名:第2263名
    • 原创:1096篇
    • 转载:14篇
    • 译文:0篇
    • 评论:5条
    最新评论