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, HttpServletResponse response) throws ServletException, IOException { System.out.println("do post"); } }
相关推荐
Juey 2014-06-03
apowerfulman 2019-07-01
luojinxu0 2019-06-30
MaureenChen 2014-06-03
donghongbz 2014-05-28
hengqiaqia 2019-06-28
wes0 2012-04-17
yFifhting 2015-10-09
85234152 2011-06-28
Ping 2014-02-22
极客园地 2013-05-11
hhboyggyy 2010-03-23
jjjjjj 2013-04-23
zwq 2013-04-11
starleejay 2013-04-09
zhangyusng 2013-04-07
沈宫新 2013-03-28
levysnail 2013-03-19