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() { $('#centent').append('<span id="lod">加载中..</span>'); //获取url var _HREF = $(this).attr('href'); //加载页面 $("#centent").load(_HREF, '', function() { $("#lod").remove(); }); return false; }); //--> </script>
The menu content implemented using post before , there is no problem
$.post(url, function(data) { $('.centent').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.