这是我的struts
<action name="GetHomePageMainAction" class="com.fullmart.control.GetHomePageAction" method="getMainChannelList">
         <result name="success">/index.jsp
         <param name="mchList"></param>
         </result>
        </action>当页面一开始加载的时候,我想通过jquery在前台获取方法getMainChannelList返回来的数据!各位如何实现。下面是我自己写的,实现不了
$(function(){
function initIndexChannel(){ $.ajax({
       type: "post",
     url: "GetHomePageMainAction.action?r="+new Date(),
     data:"mchList",
       success: function(data){
    alert(data.name);
        }
    });
  }
  initIndexChannel();
});strutsfunctionjquery

解决方案 »

  1.   

    在DOM加载完成时运行的代码,可以这样写:jQuery 代码:
    $(document).ready(function(){
      // 在这里写你的代码...
    });描述:
    使用 $(document).ready() 的简写,同时内部的 jQuery 代码依然使用 $ 作为别名,而不管全局的 $ 为何。jQuery 代码:
    $(function($) {
      // 你可以在这里继续使用$作为别名...
    });定义了initIndexChannel();又在里面调用,会形成死循环吧。
      

  2.   

    LZ写法有误,格式应该这样写:$(function(){
        $.ajax({
           type: "post",
           url: "GetHomePageMainAction.action?r="+new Date(),//在这可以不用传参
           data:{'r':new Date()},//需要传递的参数
           success: function(data){
              alert(data.name);
           }
        });
    });
    而且url只是请求action的地址,无需传参;参数一般放在data里。
      

  3.   

    你在action里有吧数据通过response返回吗吧action的代码添出来看看