Home>

The bug in the php project that has not been resolved last night was finally solved just now.I also need to thank you for your help!

Specific problem description

Recently encountered a very difficult problem,It's also because I just started thinkphp. During the project,Because very many query conditions are required,If the form is submitted by get,It will report an error because of the url length limitation.Therefore, the form data must be submitted using the post method.But during the paging process,Encountered a problem,Because the pagination that comes with thinkphp is in the form of a tag,Go to the next page,In this way, the query conditions are not passed into the background.When clicking the next page,A blank appears.

Checked the official thinkphp manual,Said that if it is a post query,How to ensure that the original query conditions can be maintained after pagination,The detailed description is shown in the following figure:

But I have a problem with the manual,Since it is paginated by a tag,So how do the parameter values ​​in $map (ie query condition parameters) be transmitted to the background?I also found some other methods online,For example, use $_request to get parameters.It is said that it includes post and get methods.But thinkphp's pagination uses the a tag to pass parameters.The parameters should still not be available,Tried it a few times,It turned out to be a failure.There are other ways,It didn't seem to work.So I asked a question on the blog last night.I was inspired by a great god,Is to modify the href attribute of the a tag with js. This really works,Then I tried all the time,Finally solved the problem.

Solution:

<html>
...
...
<body>
<form action="" method="post">
....
....
</for>
...
...
<!-Pagination->
<div>
   <div>{$page}</div>
</div>
...
...
<script type="text/javascript">
  $(function () {
     //Pagination (modify link method)
    $("#pagebar a"). click (function () {
      var tmphref=$(this) .attr ("href");
      tmphref=tmphref.replace (/\/selcon \ //, "");
      $("#form"). attr ("action", tmphref);
      $("#form"). submit ();
      return false;
    });
  }
</script>
</body>
</html>

Among them, selcon is the parameters in the form,For example name="selcon.a", name="selcon.b" ...

According to the method above, when clicking the next page,The query parameter cannot be passed.But I found another problem,In other words, when we enter the second page,Then change the query conditions,The query result does not start from the first one.But from the second page,So we also need to set the p parameter (current page number) to 1 in JS when querying. The specific method is as follows:

<script type="text/javascript">
  $(function () {
    //Inquire
    $("#selecting"). click (function () {
      $("#form"). attr ("action", "__url __/listdept/p/1");
      $("#form"). submit ();
    });
  }
</script>
php
  • Previous jQuery implements the method of serializing form elements into json objects
  • Next Share php code to convert sqlite database file of favdb exported by 360 browser to html