Ajax implements the modification function and ajax implements the modification
During this time, I was working on a project and found that I forgot so quickly. Fortunately, I have a blog garden to help me remember it. Organizing the blog garden should not be too important.
Because an internal management system only uses one home page and does not allow the whole web page to be refreshed, we can only use ajax
To do this, of course, we have also taken a lot of detours at the beginning, and we are quite pleased with the fact that we finally made this.
Today, I want to sort out the ajax implementation and modification functions. Here, login is not written, mainly to write the modified general code for future convenience.
Search when using
The style is bootstrap. At the beginning, we need to introduce three files. Here we will not talk about it. below is the style to be displayed on the page.
<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 "> × </button>
Of course, there is also a modified button to be clicked to trigger the event.
<Input type = 'bucket' class = 'xiugai' value = 'modify 'data-toggle = 'modal' data-target = '# mymodal' ids0 =' {$ v [0 ]} 'ids1 = '{$ att [0] [0]} 'ids2 =' {$ v [2]} 'ids3 =' {$ v [3]} 'ids4 = '{$ ann [0] [0]}'/> // The value is obtained by using the php code, I will not talk about it here.
The following is the ajax part. For convenience, I wrote the modification as a method and called it directly.
Function xiugai () {var ids = ""; // It is first defined as empty var rmc1 = ""; var rsl1 = ""; var rqi1 = ""; var rcg1 = ""; $ (". xiugai "). click (function () {// click an event ids =$ (this) for the modify button ). attr ("ids0"); rmc1 = $ (this ). attr ("ids1"); // obtain the previous value and assign it to val rsl1 = $ (this) in the form ). attr ("ids2"); rqi1 = $ (this ). attr ("ids3"); rcg1 = $ (this ). attr ("ids4"); $ ("# rmc "). val (rmc1); $ ("# rsl "). val (rsl1); $ ("# rqi "). val (rqi1); $ ("# rcg "). val (rcg1); $ ("# rcbtn "). click (function () {var rmc =$ ("# rmc "). val (); var rsl = $ ("# rsl "). val (); var rqi = $ ("# rqi "). val (); var rcg =$ ("# rcg "). val (); $. ajax ({url: "xiugai. php ", data: {ids: ids, rmc: rmc, rsl: rsl, rqi: rqi}, type:" POST ", dataType:" TEXT ", success: function (xx) {// alert (xx); if (xx. trim () = "OK") {alert ("modified successfully"); Load () ;}}) $ ('# mymodal '). modal ('hide ')})});}
<?php$ids=$_POST["ids"];$rmc=$_POST["rmc"];$cgsl=$_POST["rsl"];$cgrq=$_POST["rqi"];include("DBDA.class.php");$db=new DBDA();$sql1="select qxdh from qxypmx where qxmc='{$rmc}'";$arr=$db->Query($sql1);$sql="update qxcg set qxdh='{$arr[0][0]}',cgsl='{$cgsl}',cgrq='{$cgrq}' where ids='{$ids}'";if($db->Query($sql,0)){ echo"OK";}else{ echo"NO";}
In this way, the modify button function can be implemented. After you click Modify, a pop-up box is displayed ,:
After modification, click Save. the pop-up box disappears and the content is saved.
The above is all the content of this article. I hope this article will help you in your study or work. I also hope to provide more support to the customer's home!