ajax

WBOY
Release: 2016-06-23 13:22:45
Original
805 people have browsed it


用Ajax实现分页功能
将获取的的数据,填充到对应的div
不知为啥 点击下一页时  滚动条跳到顶端 但是网页又没刷新,链接也没变

<body><div>    </br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br>    </br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br>    </br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></div><div id="a1">    <{section name=s loop=$newsinfo}>    <{$newsinfo[s].id}>----<{$newsinfo[s].title_tc}></br>    <{/section}></div><div id="a2">    <{$news->page->getPageNavTeacherShare3('index.php')}></div></body>
Copy after login

<script> function A(a){     $.ajax({         url: 'a.php',         type: 'post',         dateType: 'json',         data: {page: a},         success: function (result) {             var result = jQuery.parseJSON(result);             var len=result.newsinfo.length;             var msg="";             for(var i=0;i<len;i++){                 msg+=result.newsinfo[i]['id']+"---"+result.newsinfo[i]['title_tc']+"</br>";             }               $('#a1').html(msg);               $('#a2').html(result.news);         },         error: function (result) {             alert("error");         }     }); }</script>
Copy after login


回复讨论(解决方案)

1、没有看到 A 函数在哪里被执行
2、如果 A 函数由 超链 触发,则 A 函数中应有 retuen false 以阻止 超链 的默认行为
3、你有 dateType: 'json',则 success: function (result) 中的 result 已是 js 对象或数组了
再 result = jQuery.parseJSON(result) 将出错,jQuery.parseJSON 的参数必须是合法的 json 格式串
4、ajax 不会修改浏览器的地址栏

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template