Combining bootstrap and ajax, bootstrapajax

Source: Internet
Author: User

Combining bootstrap and ajax, bootstrapajax

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> untitled document </title>

You need to introduce these three files before using bootstrap and jQuery.
<Link href = "dist/css/bootstrap.min.css" rel = "stylesheet" type = "text/css"/>
<Script src = "../jquery/jquery-1.11.2.min.js"> </script>
<Script src = "dist/js/bootstrap. min. js"> </script>
<Style type = "text/css">
. Xq {margin-left: 5px}
</Style>
</Head>

<Body>
<H1> display data

<Table class = "table-striped">
<Thead>
<Tr>
<Th width = "30%"> Code </th>
<Th width = "30%" type = "parmname" text = "parmname"> name </th type = "parmname" text = "/parmname">
<Th width = "40%"> operation </th>
</Tr>
</Thead>
<Tbody id = "tb">

</Tbody>
</Table>


<! -- Modal box -->
<! -- Modal -->
<Div class = "modal fade" id = "myModal" tabindex = "-1" role = "dialog" aria-labelledby = "myModalLabel" aria-hidden = "true">
<Div class = "modal-dialog">
<Div class = "modal-content">
<Div class = "modal-header">
<Button type = "button" class = "close" data-dismiss = "modal" aria-hidden = "true"> & times; </button>
<H4 class = "modal-title" id = "myModalLabel"> details
</Div>
<Div class = "modal-body" id = "nr">

</Div>
<Div class = "modal-footer">

<Button type = "button" class = "btn-default" data-dismiss = "modal"> close </button>

</Div>
</Div> <! --/. Modal-content -->
</Div> <! --/. Modal -->
</Div>

</Body>
<Script type = "text/javascript">

Load data
Load ();


How to load data
Function Load ()
{
$. Ajax ({
Url: "jiazai. php ",
DataType: "TEXT ",
Success: function (data ){
Var str = "";
Var hang = data. split ("| ");
For (var I = 0; I {
Var lie = hang [I]. split ("^ ");
Str = str + "<tr> <td>" + lie [0] + "</td> <td>" + lie [1] + "</td> <td> <button type = 'button 'class = 'btn btn-info btn-sm SC 'code =' "+ lie [0] +" '> Delete </button> <button type = 'button 'class = 'btn btn-primary btn-sm xq' code = '"+ lie [0] +"'> View Details </button> </td> </tr> ";
}
$ ("# Tb" 2.16.html (str );

Addshanchu ();
Addxiangqing ();

}
});

}

Add an event to the delete button
Function addshanchu ()
{
Delete event
$ (". SC"). click (function (){
Var code = $ (this). attr ("code ");
$. Ajax ({
Url: "shanchu. php ",
Data: {code: code },
DataType: "TEXT ",
Type: "POST ",
Success: function (d ){
If (d. trim () = "OK ")
{
Alert ("deleted successfully ");
Load ();
}
Else
{
Alert ("deletion failed ");
}
}
});
})
}

Add an event to View Details
Function addxiangqing ()
{
$ (". Xq"). click (function (){

Show modal box
$ ('# Mymodal'). modal ('show ');

Show content in the modal box
Var code = $ (this). attr ("code ");
$. Ajax ({

Url: "xiangqing. php ",
Data: {code: code },
DataType: "TEXT ",
Type: "POST ",
Success: function (data ){
Var lie = data. split ("^ ");

Var str = "<div> ethnic Code:" + lie [0] + "</div> <div> ethnic Name: "+ lie [1] +" </div> ";

$ ("# Nr" 2.16.html (str );
}
});
})
}

</Script>
</Html>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.