首页 新闻 搜索 专区 学院

jQuery,返回undefined,急急急,求助啊~

0
悬赏园豆:10 [已解决问题] 解决于 2012-05-10 15:53
View Code
 1 <div >
 2         <h1 >
 3             <b >短信列表</b> <span ></span>
 4         </h1>
 5         <div >
 6             <div >
 7                 <%--<div >
 8                     <table >
 9                         <tr>
10                             <td>
11                                 <input type="text" runat="server" />
12                             </td>
13                             <td>
14                                 <a type="" ><span><em>查询</em> </span></a>
15                             </td>
16                         </tr>
17                     </table>
18                 </div>--%>
19                 <table >
20                     <thead>
21                         <tr>
22                             <th >
23                                 序号
24                             </th>
25                             <th >
26                                 内容
27                             </th>
28                             <th >
29                                 创建时间
30                             </th>
31                             <th >
32                                 操作
33                             </th>
34                         </tr>
35                     </thead>
36                     <tbody>
37                     </tbody>
38                 </table>
39                 <div >
40                 </div>
41             </div>
42         </div>
43     </div>

这个上面是弹出层,

View Code
 <img src="/images/MemberMaimage.jpg" alt="" />
                    <a href="#name" class="xz_Message" style="color: Blue; font-family: 微软雅黑; font-size: 13px;">使用已保存的短信</a>

这个上面是按钮,

View Code
//总页数
var pageCountgoods = 0;
// 页数变量
var currentPageIndexgoods = 1;
//显示数据
function showPageListgoods(cPagegoods) {
    //前一页和最后一页需要
    currentPageIndexgoods = cPagegoods;
    $("#onSalegoods tbody").children("tr").remove();
    //alert("sdf");
    $.ajax({
        type: "POST",
        contentType: "application/json",
        url: "MemberMaintenance.aspx/GetMessageList",
        data: "{currentPagegoods:'" + cPagegoods + "'}",
        async: false,
        dataType: "json",
        cache: false,
        success: function (result) {           
            var list = result.d.List;
            //alert(list);
            pageCountgoods = result.d.PageCount;
            if (list != null) {
                var tdHtmlgoods1 = "<tr><td class='textC'>";
                var tdHtmlgoods2 = "</td><td>";
                var tdHtmlgoods3 = "</td><td>";
                var tdHtmlgoods4 = "</td><td class='textC'><a content='";
                var tdHtmlgoods5 = "' title='选择短信' class='icon16 iconHand j_addgoods w20'></a></td></tr>";
                $.each(list, function (i) {
                    appendgoodsStr = tdHtmlgoods1 + list[i].TemplateID + tdHtmlgoods2 + list[i].TemplateContent + tdHtmlgoods3 + list[i].Createtime + tdHtmlgoods4 + list[i].TemplateContent + tdHtmlgoods5;

                    $("#onSalegoods tbody").append(appendgoodsStr);
                }); //end $.each(list, function (i)
            } //end if(list != null)
        }, //end success: function (result)
        error: function (error) {
            alert('error:' + error);
        } //end error: function (error)

    }); //end $ajax

    //显示页数
    showPagergoods(pageCountgoods, cPagegoods);
} // end 显示数据

// 显示分页 pageCount:总页数 currentPageindex:当前页数
function showPagergoods(pageCountgoods, currentPageindexgoods) {

    var pageHtmlgoods = "";
    pageHtmlgoods += '<span class="fr mr10"><a class="page-icon iconFirst"></a><a class="page-icon iconBack"></a><span class="pagerIndex">';

    // 前半部分
    if (currentPageindexgoods < 6) {
        for (var i = 1; i < currentPageindexgoods; i++) {
            if (currentPageindexgoods != i) {
                pageHtmlgoods += "<a href='javascript:showPageListgoods(" + i + ");'>" + i + "</a>";
            } else {
                pageHtmlgoods += "<a class='on'>" + i + "</a>";
            }
        }
    }
    else {
        for (var i = currentPageindexgoods - 5; i < currentPageindexgoods; i++) {
            if (currentPageindexgoods != i) {
                pageHtmlgoods += "<a href='javascript:showPageListgoods(" + i + ");'>" + i + "</a>";
            } else {
                pageHtmlgoods += "<a class='on'>" + i + "</a>";
            }
        }
    }
    // 后半部分
    if (currentPageindexgoods < pageCountgoods - 5) {
        for (var i = currentPageindexgoods; i < currentPageindexgoods + 6; i++) {
            if (currentPageindexgoods != i) {
                pageHtmlgoods += "<a href='javascript:showPageListgoods(" + i + ");'>" + i + "</a>";
            } else {
                pageHtmlgoods += "<a class='on'>" + i + "</a>";
            }
        }
    }
    else {
        for (var i = currentPageindexgoods; i <= pageCountgoods; i++) {
            if (currentPageindexgoods != i) {
                pageHtmlgoods += "<a href='javascript:showPageListgoods(" + i + ");'>" + i + "</a>";
            } else {
                pageHtmlgoods += "<a class='on'>" + i + "</a>";
            }
        }
    }
    pageHtmlgoods += '</span><a class="page-icon iconNext">';
    pageHtmlgoods += ' </a><a class="page-icon iconLast"></a></span>';

    $("#searchPagergoods").html(pageHtmlgoods);

    var prepage = currentPageIndexgoods - 1 > 0 ? currentPageIndexgoods - 1 : 1;
    var nextpage = currentPageIndexgoods + 1 < pageCountgoods ? currentPageIndexgoods + 1 : pageCountgoods;
    if (prepage != pageCountgoods) {
        $(".iconNext,").click(function () {
            showPageListgoods(nextpage);
        });
        $(".iconLast").click(function () {
            showPageListgoods(pageCountgoods);
        });
    }
    if (currentPageIndexgoods != 1) {
        $(".iconBack,").click(function () {
            showPageListgoods(prepage);
        });
        $(".iconFirst").click(function () {
            showPageListgoods(1);
        });
    }

} //end 显示分页

//选择宝贝点击事件
$('#choosegoods').jqm({
    trigger: '.xz_Message',
    overlay: 60,
    overlayClass: 'whiteOverlay'
}).jqDrag('.jqDrag');
//$('.xz_Message').live('click', function () {
$('.xz_Message').click(function () {


    $('#choosegoods').jqmShow();
    //alert("sdsds");
    //显示数据
    showPageListgoods(1);
});   //end $('.chooseGoodsBtn').click(function () {


/*选择按钮点击事件*/
$('#onSalegoods .j_addgoods').live('click', function () {
    //$('#onSalegoods .j_addgoods').click(function () {
    //alert("dsd");
    var contentstr = $(this).attr('content');
    $('#MainContent_txtMessage').val(contentstr);
    $('#choosegoods').jqmHide();
});        //end $('#onSalegoods .j_addgoods').live('click', function () {

这个是JS代码,js分页代码,

现在是我点击按钮,弹出层,然后里面有分页,我冲数据库里取出数据返回LIST,

View Code
 /// <summary>
        /// 获取短信-短信列表
        /// gwd 2012.5.9-1513
        /// </summary>
        /// <returns></returns>
        [WebMethod]
        public static object GetMessageList(int currentPagegoods)
        {
            Moon_MessageTemplateBLL messageTemplateBLL = new Moon_MessageTemplateBLL();
            int pageSize = int.Parse(ConfigurationManager.AppSettings["JS_PageSize"]);
            //DataSet dss = new DataSet();
            //dss = messageTemplateBLL.GetPagedDataSetCustomerByNote(currentPagegoods, pageSize, out totalCountMessage);
            List<Moon_MessageTemplateEntity> dss = Moon_MessageTemplateBLL.GetPagedDataSetCustomerByNoteGWD(currentPagegoods, pageSize, out totalCountMessage);//.GetRecommendPageList(qList, currentPage, pageSize, out totalCount);
            
            double pageCount = Math.Ceiling((double)totalCountMessage / pageSize);

            return new { List = dss, PageCount = pageCount };
        }

这是获取LIst的方法,但是每次弹出层,里面时间这个字段,老是创建时间这个字段为undefined:

嗯,就是不出时间,字段也没错啊~~

多情自古伤离别的主页 多情自古伤离别 | 初学一级 | 园豆:129
提问于:2012-05-10 09:38
< >
分享
最佳答案
1

应该是你的result.d.List的数据中,创建日期不是Createtime或者没有这个属性。

收获园豆:2
无之无 | 大侠五级 |园豆:5085 | 2012-05-10 09:49
View Code
 List<Moon_MessageTemplateEntity> dss = Moon_MessageTemplateBLL.GetPagedDataSetCustomerByNoteGWD(currentPagegoods, pageSize, out totalCountMessage);//.GetRecommendPageList(qList, currentPage, pageSize, out totalCount);
            
            double pageCount = Math.Ceiling((double)totalCountMessage / pageSize);

            return new { List = dss, PageCount = pageCount };

这个是用List集合获取的短信表,有CreateTime啊,可是分页的时候,返回就是Undefined

多情自古伤离别 | 园豆:129 (初学一级) | 2012-05-10 10:00
其他回答(4)
1

ajax返回的数据 result.d.List 是什么样的 ?

收获园豆:2
草根程序猿 | 园豆:129 (初学一级) | 2012-05-10 09:43

什么 我不太理解?

支持(0) 反对(0) 多情自古伤离别 | 园豆:129 (初学一级) | 2012-05-10 10:00

@多情自古伤离别: 

$.ajax({
        type: "POST",
        contentType: "application/json",
        url: "MemberMaintenance.aspx/GetMessageList",
        data: "{currentPagegoods:'" + cPagegoods + "'}",
        async: false,
        dataType: "json",
        cache: false,
        success: function (result) {           
            var list = result.d.List;

你可以在浏览器(FireFox的firebug中或chrome)中看到result.d.List的值的

支持(0) 反对(0) 草根程序猿 | 园豆:129 (初学一级) | 2012-05-10 10:02

@菜鸟程序猿: 在这里看:

支持(0) 反对(0) 草根程序猿 | 园豆:129 (初学一级) | 2012-05-10 10:42

@菜鸟程序猿: 

{"d":{"List":[{"ID":178,"TemplateID":70,"TemplateTitle":null,"TemplateContent":"编辑新短信","Creater":"asf",
"CreateTime":"\/Date(1336618729397)\/","Remark":"无备注消息"},{"ID":175,"TemplateID":67,"TemplateTitle":null
,
"TemplateContent":"保存成功保存成功","Creater":"asf","CreateTime":"\/Date(1336618713520)\/","Remark":"无备注消息"
}
,{"ID":177,"TemplateID":69,"TemplateTitle":null,"TemplateContent":"海恩那个","Creater":"asf","CreateTime"
:"
\/Date(1336618232343)\/","Remark":"无备注消息"},{"ID":176,"TemplateID":68,"TemplateTitle":null,"TemplateContent"
:
"怎么会这样呢,拿到是js 怎么会这样呢,拿到是js 怎么会这样呢,拿到是js 怎么会这样","Creater":"asf","CreateTime":"\/Date(1336614648357)\
/","Remark":"无备注消息"},{"ID":149,"TemplateID":43,"TemplateTitle":"编辑新短信","TemplateContent":"保存成功","Creater":"asf","CreateTime":"\/Date(1336551773470)\/","Remark":"无备注消息"}],"PageCount":9}}
支持(0) 反对(0) 多情自古伤离别 | 园豆:129 (初学一级) | 2012-05-10 11:38

@多情自古伤离别: 是 CreateTime 不是 Createtime

支持(0) 反对(0) artwl | 园豆:16526 (专家六级) | 2012-05-10 13:08

@artwl: 好吧,我蒙圈了

支持(0) 反对(0) 多情自古伤离别 | 园豆:129 (初学一级) | 2012-05-10 15:51
1

能查看数据库里有值了吗?或者是字段没写对?

收获园豆:2
heqichang | 园豆:275 (菜鸟二级) | 2012-05-10 09:58

数据库有值  好多的

支持(0) 反对(0) 多情自古伤离别 | 园豆:129 (初学一级) | 2012-05-10 10:31
1

最好能看一下返回值是什么样的,看了返回值之后,应该问题所以就一目了然了

收获园豆:2
sinhbv | 园豆:2579 (老鸟四级) | 2012-05-10 10:08

不会啊~~~

支持(0) 反对(0) 多情自古伤离别 | 园豆:129 (初学一级) | 2012-05-10 10:32

@多情自古伤离别: chrome下按F12,然后network里,选中相应的请求,查看response

支持(0) 反对(0) sinhbv | 园豆:2579 (老鸟四级) | 2012-05-10 10:58

@菜鸟程序猿: 

{"d":{"List":[{"ID":178,"TemplateID":70,"TemplateTitle":null,"TemplateContent":"编辑新短信","Creater":"asf",

"CreateTime":"\/Date(1336618729397)\/","Remark":"无备注消息"},{"ID":175,"TemplateID":67,"TemplateTitle":null
,
"TemplateContent":"保存成功保存成功","Creater":"asf","CreateTime":"\/Date(1336618713520)\/","Remark":"无备注消息"
}
,{"ID":177,"TemplateID":69,"TemplateTitle":null,"TemplateContent":"海恩那个","Creater":"asf","CreateTime"
:"
\/Date(1336618232343)\/","Remark":"无备注消息"},{"ID":176,"TemplateID":68,"TemplateTitle":null,"TemplateContent"
:
"怎么会这样呢,拿到是js 怎么会这样呢,拿到是js 怎么会这样呢,拿到是js 怎么会这样","Creater":"asf","CreateTime":"\/Date(1336614648357)\
/","Remark":"无备注消息"},{"ID":149,"TemplateID":43,"TemplateTitle":"编辑新短信","TemplateContent":"保存成功","Creater":"asf","CreateTime":"\/Date(1336551773470)\/","Remark":"无备注消息"}],"PageCount":9}}
支持(0) 反对(0) 多情自古伤离别 | 园豆:129 (初学一级) | 2012-05-10 11:38

@多情自古伤离别: 明显你拼错名字了,应该用CreateTime而不是Createtime

支持(0) 反对(0) sinhbv | 园豆:2579 (老鸟四级) | 2012-05-10 11:43

@多情自古伤离别: CreateTime啊!!!大小写!!!

支持(0) 反对(0) 无之无 | 园豆:5085 (大侠五级) | 2012-05-10 13:30
1

建议装个FireBug调试下 查看返回的JSON数据值。

比如这样:

收获园豆:2
小菜接口 | 园豆:197 (初学一级) | 2012-05-10 10:47

杯具  调试出了 这么些东西 感情那好像手机号 啊,我那是时间怎么变手机号了?

 

{"d":{"List":[{"ID":178,"TemplateID":70,"TemplateTitle":null,"TemplateContent":"编辑新短信",
"Creater":"asf"
,"CreateTime":"\/Date(1336618729397)\/","Remark":"无备注消息"},
{"ID":175,"TemplateID":67,"TemplateTitle":null
,"TemplateContent":"保存成功保存成功","
Creater":"asf","CreateTime":"\/Date(1336618713520)\/","Remark":"无备注消息"
},{"ID":177,"
TemplateID":69,"TemplateTitle":null,"TemplateContent":"海恩那个","Creater":"asf",
"CreateTime"
:"\/Date(1336618232343)\/","Remark":"无备注消息"},{"ID":176,"TemplateID"
:68,"TemplateTitle":null,"TemplateContent"
:"怎么会这样呢,拿到是js 怎么会这样呢,
拿到是js 怎么会这样呢,拿到是js 怎么会这样","Creater":"asf","CreateTime":"\/Date
(1336614648357)\
/","Remark":"无备注消息"},{"ID":149,"TemplateID":43,"TemplateTit
le":"编辑新短信","TemplateContent":"保存成功","Creater"
:"asf",
"CreateTime":"\/Date(1336551773470)\/","Remark":"无备注消息"}],"PageCount":9}}


 

支持(0) 反对(0) 多情自古伤离别 | 园豆:129 (初学一级) | 2012-05-10 11:10

@多情自古伤离别: 

支持(0) 反对(0) 多情自古伤离别 | 园豆:129 (初学一级) | 2012-05-10 11:43
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册