Home  >  Article  >  Backend Development  >  javascript - Questions about data obtained by ajax

javascript - Questions about data obtained by ajax

WBOY
WBOYOriginal
2016-12-01 00:25:571087browse

There is ul in a.html, and now there are three li in ul. Now I get the corresponding data through ajax every time I click on one li.
Then there are three a tags in b.html. How can I achieve this? Click the a tag in b.html to jump to the corresponding li in a.html and get the corresponding data? ? ? javascript - Questions about data obtained by ajax
javascript - Questions about data obtained by ajax

Reply content:

There is ul in a.html, and now there are three li in ul. Now I get the corresponding data through ajax every time I click on one li.
Then there are three a tags in b.html. How can I achieve this? Click the a tag in b.html to jump to the corresponding li in a.html and get the corresponding data? ? ? javascript - Questions about data obtained by ajax
javascript - Questions about data obtained by ajax

The following is pseudo code for reference only

b.html

<code><a href="a.shtml?li=0>跳转到LI_A并取得数据</a></code>

a.html

<code><li class="myli">li_a</li>
<li class="myli">li_b</li>
<li class="myli">li_c</li>

$('.myli').click(function () {
    loadData($(this).index());
});

// 进入页面判断参数,然后点击对应LI标签
window.onload = function () {
    var index = getQuery('li')
    $('.myli').get(index).click();
}</code>

<code>这个demo你看下:
前台:
<html>
    <meta charset="utf-8">

    <head>
        <script type="text/javascript" src="jquery.min.js"></script>
        <script type="text/javascript">
$(function()
{
    $(document).on('mouseout', '[name="state"]', function()
    {
        var html;
        var partialState = $(this).val();
        $.getJSON("getStates.php",
        {
            partialState: partialState
        }, function(states)
        {
            $('input').val(states[0]);
            $.each(states, function(i, value)
            {
                html += value;
                $("#results").html(html);
            });
        });

    });
});

        </script>
    </head>

    <body>
        <input type="text" name="state" autocomplete="off" />
        <br>
        <div id="results"> </div>
    </body>

</html>

后台:
<?php
  error_reporting(E_ALL);
  ini_set('display_errors', 1);

  $con = mysqli_connect("localhost", "root", "")
  or die("Failed to connect to the server: " . mysql_error());

  mysqli_select_db($con, "dedecms")
  or die("Failed to connect to the database: " . mysql_error());

  $partialStates = strtoupper($_GET['partialState']);

  if(!$partialStates)
  {
     echo "###";
  }
  else
  {
     $states = mysqli_query($con,"select typename  from dede_arctype where typename like '%$partialStates%'") or die(mysql_error());
     $sources = array();
   while($row = mysqli_fetch_array($states)) {
       $sources[] = $row['typename'];
   }
   header('Content-Type: application/json');
   echo json_encode($sources);
  }
</code>
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