JSONÀý×Ó£¨struts ajax json£©
À´Ô´£ºhaoxuewu - BlogJava
¡¡¡¡Ç°¶Îʱ¼ä×öÏîÄ¿Óõ½ÁËjson£¬½ñÌìÎÒ³éʱ¼äдÁËÒ»¸östruts+ajax+jsonµÄÀý×Ó.
¡¡¡¡¸öÈ˸оõajax+jsonÔںܴó³Ì¶ÈÉϽµµÍÁËÍøÂçºÍ·þÎñÆ÷µÄIO£¬ÊÇÒ»¸öºÜ²»´íµÄ×éºÏ£¡
¡¡¡¡1£ºjsonµÄlibÎÒÓõÄÊÇjson-lib-2.1-jdk15.jar£¬Ëü¿ÉÒÔÔÚ
¡¡¡¡2£ºstrutsÓõÄÊÇ1.2
¡¡¡¡3£ºÓõ½ÁËjsµÚÈý·½prototype.js£¬Ö÷ÒªÓÃËü°ü×°µÄajax¶ÔÏ󣬴ó¼ÒҲû±ØÒªÓÃÕâ¸ö£¬¿ÉÒÔÖ±½ÓÔÚjsÀïÓÃXMLHttpRequest¡£
¡¡¡¡ÒÔÏÂÊÇÀý×ÓÖÐËùÓõ½µÄÏà¹ØÎļþ£º
/////////////////////////////////////// toolhxw.js
/**
@hxw 20080602
*/
//»Øµ÷º¯Êý ¼òµ¥»Øµ÷º¯Êý
function showesay(dataResponse)
{
var data = eval('(' + dataResponse.responseText + ')');
var str='';
str+='£¼ul£¾';
str+='£¼li£¾'+data.param1; +'£¼/li£¾';
str+='£¼li£¾'+data.param2; +'£¼/li£¾';
str+='£¼/ul£¾';
document.getElementById("content").innerHTML=str;
}
//»Øµ÷º¯Êý ¸´Ôӻص÷º¯Êý
function showcomplex(dataResponse)
{
var data = eval('(' + dataResponse.responseText + ')');
var str='';
for(var i=0; i£¼data.js.length; i++)
{
str+='£¼ul£¾';
str+='£¼li£¾'+data.js[i].id+'£¼/li£¾';
str+='£¼li£¾'+data.js[i].age+'£¼/li£¾';
str+='£¼li£¾'+data.js[i].name+'£¼/li£¾';
str+='£¼li£¾'+data.js[i].address+'£¼/li£¾';
str+='£¼/ul£¾';
}
document.getElementById("content").innerHTML=str;
}
//»ñÈ¡¼òµ¥µÄjsonÊý¾Ý
function getesay(){
var url = 'test.do';
var pars = 'method=getEasy';
var ajax = new Ajax.Request(
url,
{method:'post',parameters:pars,onComplete:showesay}
);
}
//»ñÈ¡¶ÔÏ󼶸´ÔÓÊý¾Ý
function getcomplex(){
var url = 'test.do';
var pars = 'method=getComplex';
var ajax = new Ajax.Request(
url,
{method:'post',parameters:pars,onComplete:showcomplex}
);
}
///////////////////////////////////////struts-config.xml
£¼?xml version="1.0" encoding="UTF-8"?£¾
£¼!DOCTYPE
struts-config PUBLIC "-//Apache Software Foundation//DTD Struts
Configuration 1.2//EN"
"http://struts.apache.org/dtds/struts-config_1_2.dtd"
Ïà¹ØÎĵµ£º
jQueryÊÇÒ»¸ö¿ÉÒÔ¼ò»¯ JavaScript?ÒÔ¼°AJAX£¨Asynchronous JavaScript
+XML£¬Òì²½JavascriptºÍXML£©±à³ÌµÄJavascript¿â¡£²»Í¬ÓÚÆäËûµÄJavascript¿â£¬jQueryÓÐËû×Ô¼ºµÄÕÜѧ£¬Ê¹Äã¿É
ÒԺܼòµ¥µÄ±àд´úÂë¡£ÕâƪÎÄÕ¾ͻá´øÁìÄã¼ûʶһÏÂjQueryµÄÕÜѧ£¬Ì½ÌÖÒ»ÏÂËûµÄÌØÐÔÒÔ¼°¹¦ÄÜ£¬²¢ÇÒ»á×öһЩajaxµÄʾÀý£¬ÒÔ¼°ÈçºÎʹÓÃplug-
......
Ò³ÃæÎļþÀàËÆ£º
<% using (Ajax.BeginForm("AjaxUpdate", 123, new AjaxOptions {
Confirm = "confirm str", LoadingElementId = "idLoading", UpdateTargetId
= "textEntered", OnSuccess = "validateForm" },new{id="idMyForm"}))
&nbs ......
Ajax¿ÉÒÔʵÏÖÍøÒ³µÄ¾Ö²¿Ë¢ÐÂ,ÊÇͨ¹ýJS»ñÈ¡Êý¾Ý,ÔÙ°ÑÊý¾ÝÌí¼Óµ½ÍøÒ³ÖÐ,È»¶øÓÉÓÚä¯ÀÀÆ÷µÄ²»Í¬,³õѧÕߺÜÄÑ×öµ½¼æÈÝÎÊÌâ.
ÕâÀïÎÒÏò´ó¼Ò½éÉÜÒ»Öֺõķ½·¨.ͨ¹ýJQuery²å¼þ.JQuery.jsÎļþ¿ÉÒÔÔÚ¹ÙÍøÉÏÏÂÔØ,»òÕßgoogleÒ²ÐÐ.
Ê×ÏÈÄãÒªÔÚÍøÒ³ÒýÈëJSÎļþ
<script src="../javascript/jquery.js" type="text/javascript"></ ......
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0044)http://www.qqip.cn -->
<HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>new document</TITLE>
<META ht ......
ajax.dllÒѾÊǺÜÀϵĶ«Î÷ÁË£¬µ«ÊǽñÌìÎÒ²ÅÓõ½Ëü£¬ÏÖÔÚ°ÑËüµÄʹÓ÷½·¨¼Ç¼ÏÂÀ´¡£
1.ÔÚweb.configÖÐÅäÖÃajaxµÄ´¦Àí³ÌÐò¡£
<httpHandlers>
<add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax" />
<httpHandlers>
2. ×¢²á´¦Àí³ÌÐòÀ࣬ajaxTestÊ ......