当前位置:Gxlcms > PHP教程 > javascript-有关于ajax获取到的数据问题

javascript-有关于ajax获取到的数据问题

时间:2021-07-01 10:21:17 帮助过:16人阅读

在a.html中有ul,现在ul中有三个li,我现在是每点击一个li通过ajax获取到对应的数据,
然后在b.html中有三个a标签,问如何能实现在b.html中单击a标签跳到a.html中对应li中并得到相应的数据???

回复内容:

在a.html中有ul,现在ul中有三个li,我现在是每点击一个li通过ajax获取到对应的数据,
然后在b.html中有三个a标签,问如何能实现在b.html中单击a标签跳到a.html中对应li中并得到相应的数据???

以下是伪代码,仅供参考

b.html

  1. <code>跳转到LI_A并取得数据</code>

a.html

  1. <code><li class="myli">li_a</li>
  2. <li class="myli">li_b</li>
  3. <li class="myli">li_c</li>
  4. $('.myli').click(function () {
  5. loadData($(this).index());
  6. });
  7. // 进入页面判断参数,然后点击对应LI标签
  8. window.onload = function () {
  9. var index = getQuery('li')
  10. $('.myli').get(index).click();
  11. }</code>

  1. <code>这个demo你看下:
  2. 前台:
  3. <meta charset="utf-8">
  4. <input type="text" name="state" autocomplete="off">
  5. <br>
  6. 后台:
  7. <!--?php
  8. error_reporting(E_ALL);
  9. ini_set('display_errors', 1);
  10. $con = mysqli_connect("localhost", "root", "")
  11. or die("Failed to connect to the server: " . mysql_error());
  12. mysqli_select_db($con, "dedecms")
  13. or die("Failed to connect to the database: " . mysql_error());
  14. $partialStates = strtoupper($_GET['partialState']);
  15. if(!$partialStates)
  16. {
  17. echo "###";
  18. }
  19. else
  20. {
  21. $states = mysqli_query($con,"select typename from dede_arctype where typename like '%$partialStates%'") or die(mysql_error());
  22. $sources = array();
  23. while($row = mysqli_fetch_array($states)) {
  24. $sources[] = $row['typename'];
  25. }
  26. header('Content-Type: application/json');
  27. echo json_encode($sources);
  28. }
  29. </code--></code>

人气教程排行