Home > php教程 > PHP开发 > thinkPHP menu and paging example based on ajax

thinkPHP menu and paging example based on ajax

高洛峰
Release: 2016-12-21 16:47:39
Original
1567 people have browsed it

The example in this article describes how thinkPHP implements menus and paging based on ajax. Share it with everyone for your reference, the details are as follows:

A category menu, implemented using ajax:

function getid(id){
$.ajax({
   url: "{:U('/Index/example')}",
   type: "POST",
   data: {id:id}
  }).success(function(data) {
   $("#centent").html(data);
  });
}
Copy after login

And using ajax for paging, this was written by someone on the Internet:

<script type="text/javascript">
<!--
$("#page_show > a").click(function() {
  $(&#39;#centent&#39;).append(&#39;<span id="lod">加载中..</span>&#39;);
  //获取url
  var _HREF = $(this).attr(&#39;href&#39;);
  //加载页面
  $("#centent").load(_HREF, &#39;&#39;, function() {
    $("#lod").remove();
  });
  return false;
});
//-->
</script>
Copy after login

The menu content implemented using post before , there is no problem

$.post(url, function(data) {
 $(&#39;.centent&#39;).html(data);
});
Copy after login

But when implemented using ajax, the correct result cannot be obtained. Paging cannot be completed.
After final thought, I changed type: "POST" to type: "GET",
the problem is solved. The post method is also submitted by POST, and ajax is also submitted by POST at the beginning. Why doesn't it work? In the end, I found out that it was still the URL. The two URLs were different.

I hope this article will help you design PHP programs based on the ThinkPHP framework.

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template