码迷,mamicode.com
首页 > Web开发 > 详细

关于ssh和ajax小小总结

时间:2015-01-23 15:55:14      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:

我是相当的不专业,写给自己看。有什么错误的话,说出来将感激不尽。

 

有两种方法异步传输

1.通过json字符串:  jsp中这么写:

$.getJSON( "details_ajaxAction",
            function(data){
              var json = eval("("+data+")");
                alert(json.length);
                for(var i=0;i<json.length;i++)
                {
                    alert(json[i].xm);
                }           
           }

struts中:<package name="ajax" extends="json-default">
              <action
                name="details_ajaxAction"
                class="StudentAction"
                method="queryDetails_ajaxInfo">
                <result name="success" type="json">
                    <param name="root">result</param>
                </result>
           
    
    </package>

后台:把想要的数据对象放到List中,

      Gosn gs= new Gosn();

      result = gs.toJson(List).toString(); //result 就是传到jsp的字符串,result一定要有get‘set方法,与struts中的result一样。

这个样子就把result传到了jsp回调函数的data中去了。

2.另一种方法,传四个List到jsp

jsp页面中这么写:$.ajax({
                        url : "details_ajaxAction?xh=" + xh1,
                        type : ‘get‘,
                        dataType : ‘json‘,
                        error : function() {
                            alert("发生了一些程序猿都不知道的错误!");
                        },
                        success : function(responseResult) {
                            $.each(responseResult.stuList,function(i, item) {
                                            });
                         
                            $.each(responseResult.skList, function(i, item) {
                                    
                            });
                            $.each(responseResult.stList, function(i, item) {
                                     
                            });
                            $.each(responseResult.xqList, function(i, item) { 
                            });
                        }
                    });

struts中:    <package name="ajax" extends="json-default">
            <action name="details_ajaxAction" class="StudentAction"
                method="queryDetails_ajaxInfo">
            <result name="success" type="json">
                <param name="includeProperties">
                stuList.*,skList.*,stList.*,xqList.*<!-- 这个要和JAVA类里面的 参数一样 并且要有set和get方法 -->
                </param>
            </result>
        </action>
    </package>

后台:定义四个 stuList,skList,stList,xqList,把想要的数据放进去就行了//要有getset方法。

这个样子就把四个list中的数据传到ajax回调函数的responseResult中了,使用的时候就是responseResult.stuList.…….

 

 

就是这个样子,没有说原理,只说了做法。

关于ssh和ajax小小总结

标签:

原文地址:http://www.cnblogs.com/wazqy/p/4244186.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!