如何重定向页面,然后用ajax数据预填充选项


How to redirect page and then pre-fill the options with ajax data?

情况是这样的:

在page1.php上,有一个数据网格,每行有一个视图链接。现在,当我点击一个视图链接,它应该重定向到另一个页面,这将是page2.php。在page2.php上,有5个复选框和一个输入表单(它实际上是一个带有提交按钮的搜索选项/功能)。我想从数据库中提取的数据预填充这些选项,这是基于从page1.php的"视图"链接的"ID",然后显示基于预填充选项的搜索结果。我该怎么做呢?

这是我当前的代码

   $('.view').click(function(){
      var id = $(this).attr('id');
      var userid = $('#userid').val();
       window.location = './page2.php';
       //I don't really know what to do here.
       //assuming the db table is named testtable?
       //am i just gonna use $.ajax() ?, if so,how will i extract the returned data
       // in order to prefill the options on page2.php and at the same time
       // show the result of the search based from the prefilled options?
   });

为什么需要AJAX呢?

你可以设置链接的HREF重定向到page2.php?var=smth,然后使用该值从数据库中提取信息与php,并根据它填充HTML表单。