Home  >  Article  >  php教程  >  thinkPHP menu and paging example based on ajax

thinkPHP menu and paging example based on ajax

高洛峰
高洛峰Original
2016-12-21 16:47:391559browse

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);
  });
}

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>

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

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

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.

Statement:
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