Home >Web Front-end >JS Tutorial >Ajax bootstrap beautifies web pages and enables page loading, deletion and viewing details

Ajax bootstrap beautifies web pages and enables page loading, deletion and viewing details

PHPz
PHPzOriginal
2018-05-22 15:55:102011browse

Bootstrap is an open source toolkit for front-end development launched by Twitter. Bootstrap provides elegant HTML and CSS specifications, which is written in the dynamic CSS language Less. Through this article, I will introduce Ajax bootstrap to beautify web pages and realize page loading, deletion and viewing details. Friends in need can refer to

Bookstrap: Beautify the page:

Bootstrap It is an open source toolkit for front-end development launched by Twitter.

It was developed by Twitter designers Mark Otto and Jacob Thornton and is a CSS/HTML framework.

Bootstrap provides elegant HTML and CSS specifications, which are written in the dynamic CSS language Less.

Bootstrap has been very popular since its launch and has been a popular open source project on GitHub, including NASA's MSNBC (Microsoft National Broadcasting Company) Breaking News.

You only need to reference some defined classes, that is, class names, to create web pages with very beautiful styles. It also supports self-adaptation and is a very good framework.

Calling file:


<link href="dist/css/bootstrap.min.css" rel="external nofollow" rel="external nofollow" rel="stylesheet" type="text/css" />
 <script src="jquery-1.11.2.min.js"></script>
 <script src="dist/js/bootstrap.min.js"></script>

[Related video recommendation: Bootstrap tutorial]

If you want to reference one of the multiple JS files containing jquery, then the jquery file must be placed first

The next step is to beautify the table

Striped table :


##

<table class="table table-striped">
 <thead>
 <tr>
  <td>代号</td>
  <td>名称</td>
  <td>操作</td>
 </tr>
 </thead>
 <tbody id="td">
 </tbody>
</table>


Add details button and change the styles of the two buttons to beautify;


$.ajax({
   url: "jiazai.php",
//  显示所有的数据不用写data
   dataType: "TEXT",
   success: function (data) {
    var str = "";
    var hang = data.split("|");
    //split拆分字符串
    for (var i = 0; i < hang.length; i++) {
     //通过循环取到每一行;拆分出列;
     var lie = hang[i].split("-");
     str = str +
      "<tr><td>"
      + lie[0] +
      "</td><td>"
      + lie[1] +
      "</td><td>" +
      "<button type=&#39;button&#39; class=&#39;btn btn-info sc&#39; ids=&#39;"+lie[0]+"&#39;>点击删除
</button><button type=&#39;button&#39; class=&#39;btn btn-primary xq&#39; ids=&#39;"+lie[0]+"&#39;>查看详情</button>" +
      //ids里面存上主键值
      "</td></tr>";
    }
    $("#td").html(str);
    //找到td把html代码扔进去
    addshanchu();
    addxiangqing();
   }
  });


View the details of the click event:


 //给查看详情加事件
 function addxiangqing()
 {
  $(".xq").click(function(){
   $(&#39;#myModal&#39;).modal(&#39;show&#39;)
   //打开模态框
   var ids = $(this).attr("ids");
   $.ajax({
    url:"xiangqing.php",
    data:{ids:ids},
    dataType:"TEXT",
    type:"POST",
     success:function(data){
     //拆分
      var lie = data.split("^");
      var str = "<p>代号:"+lie[0]+"</p><p>名称:"+lie[1]"</p>";
      //造字符串
      var str = "<p>代号:"+lie[0]+"</p><p>名称:"+lie[1]+"</p>";
      $("#nr").html(str);
   }
   });
   //在模态框里面要显示的内容
  })
 }


The next step is the details Processing page:


<?php
$ids = $_POST["ids"];
include ("db.class.php");
$db = new db();
$sql = "select * from min where ids = &#39;{$ids}&#39;";
echo $db->strQuery($sql);


Here the splicing string and the call are written into the encapsulation class file, so strQuery is directly referenced Just fine

Picture:

Total page code:

Form page:





 
 无标题文档
 <link href="dist/css/bootstrap.min.css" rel="external nofollow" rel="external nofollow" rel="stylesheet" type="text/css" />
 <script src="jquery-1.11.2.min.js"></script>
 <script src="dist/js/bootstrap.min.js"></script>



显示数据

<table class="table table-striped"> <thead> <tr> <td>代号</td> <td>名称</td> <td>操作</td> </tr> </thead> <tbody id="td"> </tbody> </table>

<script> //调用load方法 load(); //把加载数据封装成一个方法 function load() { $.ajax({ url: "jiazai.php", // 显示所有的数据不用写data dataType: "TEXT", success: function (data) { var str = ""; var hang = data.split("|"); //split拆分字符串 for (var i = 0; i < hang.length; i++) { //通过循环取到每一行;拆分出列; var lie = hang[i].split("-"); str = str + "<tr><td>" + lie[0] + "</td><td>" + lie[1] + "</td><td>" + "<button type=&#39;button&#39; class=&#39;btn btn-info sc&#39; ids=&#39;"+lie[0]+"&#39;>点击删除</button><button type=&#39;button&#39; class=&#39;btn btn-primary xq&#39; ids=&#39;"+lie[0]+"&#39;>查看详情</button>" + //ids里面存上主键值 "</td></tr>"; } $("#td").html(str); //找到td把html代码扔进去 addshanchu(); addxiangqing(); } }); } //给查看详情加事件 function addxiangqing() { $(".xq").click(function(){ $(&#39;#myModal&#39;).modal(&#39;show&#39;) //打开模态框 var ids = $(this).attr("ids"); $.ajax({ url:"xiangqing.php", data:{ids:ids}, dataType:"TEXT", type:"POST", success:function(data){ //拆分 var lie = data.split("^"); // var str = "<p>代号:"+lie[0]+"</p><p>名称:"+lie[1]"</p>"; //造字符串 var str = "<p>代号:"+lie[0]+"</p><p>名称:"+lie[1]+"</p>"; $("#nr").html(str); } }); //在模态框里面要显示的内容 }) } //把删除事件封装成方法: function addshanchu() { //给删除按钮加上事件 $(".sc").click(function () { var ids = $(this).attr("ids"); $.ajax({ url: "shanchu.php", data: {ids: ids}, dataType: "TEXT", type: "POST", success: function (d) { if (d.trim() == "ok") { alert("删除成功"); //调用加载数据的方法 load(); } else { alert("删除失败"); } } }); }) } </script>


Loading:


<?php
include ("db.class.php");
$db = new db();
$sql = "select * from min";
$arr = $db->Query($sql);
//遍历
$str="";
foreach ($arr as $v)
{
 $str = $str.implode("-",$v)."|";
 //用-把$v拼起来,拼出来是1-红2-蓝,用|分割,拼出来是1-红|2-蓝|
}
$str = substr($str,0,strlen($str)-1);
//截取字符串:从第0个开始,截取它的长度-1
//strlen获取字符串长度
echo $str;


Delete processing page



<?php
include ("db.class.php");
$db = new db();
$ids = $_POST["ids"];
$sql = "delete from min WHERE ids=&#39;{$ids}&#39;";
if($db ->Query($sql,0))
{
 echo "ok";
}
else{
 echo "no";
}


Details processing page:



<?php
$ids = $_POST["ids"];
include ("db.class.php");
$db = new db();
$sql = "select * from min where ids = &#39;{$ids}&#39;";
echo $db->strQuery($sql);


The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Struts2 and Ajax data interaction (graphic tutorial)

##MUi Framework

ajaxRequest WebService interface instance_AJAX related

Native

ajaxWritten pull-up loading example (graphic tutorial)


The above is the detailed content of Ajax bootstrap beautifies web pages and enables page loading, deletion and viewing details. For more information, please follow other related articles on the PHP Chinese website!

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