赞
踩
-
-
-
- <?php
-
- require_once('business.php')
-
- switch(isset($_POST['service'])? $_POST['service'] : 'disp' ) {
- case 'add': return add($_POST['name'],$_POST['content']);
- case 'disp': return disp();
- case 'modify': return modify($_POST['id'],$_POST['name'],$_POST['content']);
- case 'del': return del($_POST['id'],$_POST['name'],$_POST['content']);
- default: break;
- }
- ?>
index.html(只完成了添加)
- <html>
- <head>
- <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"></script>
- <script type="text/javascript">
- $(document).ready(function(){
- $('#bt1').click(function(){
- var postdata = 'service=add&name='+$('#name').val()+'&content='+$('#content').val()
- htmlobj=$.ajax({
- type: 'POST',
- url: './bookmarklet.php',
- data: postdata,
- timeout:8000,
- async: false,
- //success: function(res) { alert(res);}
- });
- alert(postdata);
- $("#responseText").html(htmlobj.responseText);
- });
- });
- </script>
- </head>
- <body>
- <div id="responseText"></div>
- <input type='text' id="name" placeholder ='名称'></div>
- <input type='text' id="content" placeholder ='javascript:XXXX...'></div>
- <input type='button' id="bt1" value='提交'></div>
- </body>
- </html>
business.php(只完成了对添加的处理)
- <?php
-
- define('DB_HOST', 'localhost');
- define('DB_USER', 'root');
- define('DB_PASSWORD', 'hello');
- define('DB_NAME', 'dlutdb');
-
- $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
- function add($name,$content){
- global $dbc;
- mysqli_query($dbc,"INSERT INTO bookmarklet(name,content) VALUES ('$name', '$content')")
- or die("Error add bookmarklet: " . mysql_error());
- }
- ?>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。