日期:2014-05-16  浏览次数:20492 次

php 怎么响应button的onclick事件
我php用的codeigniter框架引用的smart模板,页面上的button事件控制器怎么响应 求高手解答,谢谢。能给个例子最好。
------解决方案--------------------
用 JS  异步请求PHP 

------解决方案--------------------
百度ajax同步异步交互技术
------解决方案--------------------
w3school上面搜jquery ajax例子就ok了
------解决方案--------------------
index.html 按钮及js执行事件

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html;charset=utf-8">
  <title> button click test </title>
  <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
  <script type="text/javascript">
  function getdata(){
$.ajax({
url: "do.php",  // 这里改成你要执行的php便可
success: function(data){
if(data.success==1){ // 根据返回的数据做不同处理
alert(data.msg);
}
}
});
  }
  </script>
 </head>

 <body>
  <input type="button" onclick="getdata()" value="执行php">
 </body>
</html>


do.php 要执行的php,根据需要写不同内容便可。

<?php
$ret = array();
$ret['success'] = 1;
$ret['msg'] = '调用php成功';
header('content-type:application/json');
echo json_encode($ret);
?>