關於ssh和ajax小小總結

來源:互聯網
上載者:User

標籤:

我是相當的不專業,寫給自己看。有什麼錯誤的話,說出來將感激不盡。

 

有兩種方法非同步傳輸

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小小總結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.