dwr_实现无刷新获取数据

前端之家收集整理的这篇文章主要介绍了dwr_实现无刷新获取数据前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

web.xml 配置:

<servlet>

<servlet-name>dwr-invoker</servlet-name>

<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>

<init-param>

<param-name>debug</param-name>

<param-value>true</param-value>

</init-param>

<load-on-startup>1</load-on-startup>

</servlet>

<servlet-mapping>

<servlet-name>dwr-invoker</servlet-name>

<url-pattern>/dwr/*</url-pattern>

</servlet-mapping>

dwr.xml:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://getahead.org/dwr/dwr20.dtd">

<dwr>

<allow>

<create creator="new" javascript="FirstDWR">

<param name="class" value="com.zte.gateway.web.am.action.FirstDWR" />

</create>

<convert match="com.zte.gateway.web.am.action.StringOBJ" javascript="StringOBJ"

converter="bean" />

</allow>

</dwr>

页面:

<%@ 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">

<script type="text/javascript" src="<%=request.getContextPath() %>/dwr/engine.js"></script>

<script type="text/javascript" src="<%=request.getContextPath() %>/dwr/util.js"></script>

<script type="text/javascript" src="<%=request.getContextPath() %>/dwr/interface/FirstDWR.js"></script>

<script type="text/javascript">

function goshow(){

FirstDWR.returnStrs("aaa",getResult);

}

var cellFuncs = [function(StringOBJ) { return StringOBJ.str; }];

function getResult(result){

dwr.util.setEscapeHtml(false);

var options = {

cellCreator:function(options){

var td = document.createElement("td");

return td;

}

};

dwr.util.addRows("pattern",result,cellFuncs,options);

}

//定时执行

//setInterval("goshow()",1000);

</script>

<title>Insert title here</title>

</head>

<body>

<input type="button" onclick="goshow()" value="查 询"/>

<table class="tdata w_4">

<thead><tr><th>值</th></tr></thead>

<tbody id="pattern"/>

<tfoot><tr><td colspan="4" class="tright"></td></tr></tfoot>

</table>

</body>

</html>

原文链接:https://www.f2er.com/ajax/166475.html

猜你在找的Ajax相关文章