dojo的ajax使用入门

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

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,IOException {
		System.out.println("do post");
	}

}
原文链接:https://www.f2er.com/dojo/291322.html

猜你在找的Dojo相关文章