为了账号安全,请及时绑定邮箱和手机立即绑定

写了一个js文件,函数加载进去了,但是里面的函数不执行,是什么原因

写了一个js文件,函数加载进去了,但是里面的函数不执行,是什么原因

刘松同学 2016-10-14 23:15:19
一个·用来处理json数据的js文件,传过来的json数据是{"infos":[{"id":402881e9564b22f701564b251aef0001,"title":"火影","publishingTime":"2016-08-02 20:05:38.0","isEditable":"true"},{"id":402881e9565a7f3601565a86f0c30001,"title":"龙珠","publishingTime":"2016-08-05 19:46:48.0","isEditable":"true"},{"id":402881e9565a7f3601565a8720ac0002,"title":"哈哈","publishingTime":"2016-08-05 19:47:00.0","isEditable":"true"},{"id":402881e9565a7f3601565a87464b0003,"title":"海贼","publishingTime":"2016-08-05 19:47:10.0","isEditable":"true"},{"id":402881e9565a7f3601565a87b47c0004,"title":"海贼王","publishingTime":"2016-08-05 19:47:38.0","isEditable":"true"}],"pageBean":{"pageSize":5,"currentPage":1,"totalPage":1,"hasPrevious":false,"HasNext":false}}处理json数据的文件是  var pageIndex = 1;//首页                $(function () {                                    ajaxGetListData(pageIndex);        });           //ajax获取列表function ajaxGetListData(index) {    $.ajax({        url: "getFirstInfoList.action",        type: "Post",        data: "page=" + index,        dataType: "json",        success: function (data) {            var htmlStr = "";            htmlStr += "<table class='tab-list' width='99%'>";            htmlStr += "<thead>";            htmlStr +="<tr class='list-header'>" +"<td width='5%'>序号</td>" +"<td width='30%'>用户ID</td>" +"<td width='20%'>标题</td>" +"<td width='20%'>创建时间</td>" +"</tr>";            htmlStr += "</thead>";            htmlStr += "<tbody>";            for (var i = 0; i < data.infos.length; i++) {                htmlStr += "<tr>";                htmlStr += "<td>" + (i+1) + "</td>"             + "<td>"+ data.infos[i].id + "</td>" + "<td>"+ data.infos[i].title+ "</td>" +"<td>"+ data.infos[i].publishingTime+ "</td>";                htmlStr += "</tr>";            }            if(data.infos.length==0){             htmlStr += "<tr style='text-align: center'><td colspan='6'><font color='#cd0a0a'>"+ '暂无记录' + "</font></td></tr>";     }            htmlStr += "</tbody>";            htmlStr += "<tfoot>";            htmlStr += "<tr>";            htmlStr += "<td colspan='3' style='text-align: left;border-right: 0px;'>";            htmlStr += "<font color='grey'>显示";                      htmlStr += "<span>每页" + data.pageBean.pageSize + "条记录_共<span id='count'>" + data.pageBean.totalPage+ "</span>页_"+"当前第"+data.pageBean.currentPage+"页" + "</span></font>";            htmlStr += "</td>";            htmlStr += "<td colspan='3' style='text-align: right;border-left: 0px;'>";                       if(data.pageBean.currentPage > 1){              htmlStr += "<a href='javascript:void' onclick='GoToFirstPage()' id='aFirstPage' >首    页</a>&nbsp;&nbsp; ";            }else{             htmlStr += "<font color='grey'>首    页</font>&nbsp;&nbsp";            }                        if((data.pageBean.currentPage - 1 ) > 0 ){             htmlStr +="<a href='javascript:void' onclick='GoToPrePage()' id='aPrePage'>上一页</a>&nbsp;&nbsp";             }else{             htmlStr +="<font color='grey'>上一页</font>&nbsp;&nbsp";              }                        if((data.pageBean.currentPage+1) > data.pageBean.totalPage){              htmlStr += "<font color='grey'>下一页</font>&nbsp;&nbsp;";            }else{               htmlStr += "<a href='javascript:void' onclick='GoToNextPage()' id='aNextPage'>下一页</a>&nbsp;&nbsp;";            }            if(data.pageBean.currentPage < data.pageBean.totalPage){             htmlStr += "<a href='javascript:void' onclick='GoToEndPage()' id='aEndPage' >尾    页</a>&nbsp;&nbsp; ";            }else{             htmlStr += "<font color='grey'>尾    页</font>&nbsp;&nbsp";            }                        htmlStr += "<input id='pageNum' name='pageNum' class='input-page' type='text' /><input type='button'  value='跳转' onclick='GoToAppointPage(this)' style='width: 60px; height: 25px;font-size: 12px;'/> ";            htmlStr += "</td>";            htmlStr += "</tr>";            htmlStr += "</tfoot>";            htmlStr += "</table>";            $("#divSearchResult").html(htmlStr);        }, error: function (XMLHttpRequest, textStatus, errorThrown) {                    alert(XMLHttpRequest);                    alert(textStatus);                    alert(errorThrown);                }    }); }        //首页        function GoToFirstPage() {            pageIndex = 1;            ajaxGetListData(pageIndex);        }        //上一页        function GoToPrePage() {            pageIndex -= 1;            pageIndex = pageIndex >= 0 ? pageIndex : 0;            ajaxGetListData(pageIndex);        }        //下一页        function GoToNextPage() {            if (pageIndex < parseInt($("#count").text())) {                pageIndex += 1;            }                ajaxGetListData( pageIndex);        }        //尾页        function GoToEndPage() {            pageIndex = parseInt($("#count").text());            ajaxGetListData(pageIndex);        }        //跳转        function GoToAppointPage(e) {            var page = $(e).prev().val();            if (isNaN(page)) {                alert("请输入数字!");            }            else {                var tempPageIndex = pageIndex;//pageIndex==currentPage                pageIndex = parseInt(page);                if (pageIndex < 0 || pageIndex > parseInt($("#count").text())) {                    pageIndex = tempPageIndex;                    alert("请输入有效的页面范围!");                }else {                    ajaxGetListData(pageIndex);                }            }        }    2016/10/12 23:53:24放下 2016/10/12 23:53:24<%@ page language="java" contentType="text/ html; charset=UTF-8" pageEncoding="UTF-8"%><%@ taglib prefix="s" uri="/struts-tags" %><%@ taglib prefix="sd" uri="/struts-dojo-tags" %><%request.setCharacterEncoding("UTF-8"); %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <script language="Javascript" src="js/XMLHttpRequestFactory.js"></script> <script language="Javascript" src="js/Asynchronous.js"></script> <script language="Javascript" src="js/AjaxList.js"></script> <head> <s:head theme="xhtml" /> <sd:head parseContent="true" /> <meta http-equiv="Content-Type" content="text/ html;charset=UTF-8">          <title>社区主页</title> </head> <body> <div>              <input type="text" id="txtSearch" />              <input type="button" id="btnSearch" value="Search" />      </div>      <div id="divSearchResult">          </div>   </body></ html>经过测试里面的函数就是不执行,有可能是什么原因
查看完整描述

2 回答

已采纳
?
一朵大白天

TA贡献54条经验 获得超14个赞

看看console报的什么错误?

查看完整回答
反对 回复 2016-10-15
?
一瞬儿光

TA贡献178条经验 获得超70个赞

从来就没有这么传data的。

查看完整回答
反对 回复 2016-10-15
  • 慕先生6180776
    慕先生6180776
    那你一般都是怎么传data的?他这个方式不就相当于url传值吗?
  • 2 回答
  • 0 关注
  • 3307 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信