Ajax 搜索结果,点击结果下载文件

我的索引页


    <html>

         <head>

          <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

          <title>Some name</title>

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

          <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

          <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />

         </head>

         <body>

          <div class="container">

           <br />

           <h2 align="center">Search by name</h2><br />

           <div class="form-group">

            <div class="input-group">

             <span class="input-group-addon">Search</span>

             <input type="text" name="search_text" id="search_text" placeholder="Enter model / search here" class="form-control" />

            </div>

           </div>

           <br />

           <div id="result"></div>

          </div>

         </body>

        </html>


    <script>

    $(document).ready(function(){


     load_data();


     function load_data(query)

     {

      $.ajax({

   url:"fetch.php",

   method:"POST",

   data:{query:query},

   success:function(data)

   {

    $('#result').html(data);

   }

  });

 }

 $('#search_text').keyup(function(){

  var search = $(this).val();

  if(search != '')

  {

   load_data(search);

  }

  else

  {

   load_data();

  }

 });

});

</script>

AND MY fetch.php PAGE,用于从数据库表中获取数据并输出结果。我还添加了如果结果 > 50 它会要求输入更多字符,因为如果我不添加 if result > 50 那么我的页面需要 20 秒才能显示所有数据,因为我的数据库表有 25000 个条目。

我想要我的每个结果的 href 链接,并且在点击时,它应该从数据库表中的 ./"URL" 列下载一个文件。

我的数据库如下所示:

http://img4.mukewang.com/62ac34430001c66517950775.jpg

我当前的页面是http://mss1996.ddns.net:8008/files

我尝试在 outpur'array' 中添加 <a href=".$row["URL"]."> 但它破坏了我的页面。



HUWWW
浏览 119回答 1
1回答

海绵宝宝撒

如果该字段的内容确实是有效的 URL,您应该能够轻松地添加该URL字段以形成有效的 URL。我看到您的代码中缺少的内容是http或者https如果它是外部链接。如果它是页面内的相对链接,那么您就可以了。然后添加</a>关闭链接。所以你会像这样形成你的表格列:echo&nbsp;'<td><a&nbsp;href="'&nbsp;.&nbsp;$row['URL']&nbsp;.&nbsp;'">'&nbsp;.&nbsp;$row["URL"]&nbsp;.&nbsp;'</a></td>';
打开App,查看更多内容
随时随地看视频慕课网APP