Home  >  Article  >  Backend Development  >  php 如何响应button的onclick事件

php 如何响应button的onclick事件

WBOY
WBOYOriginal
2016-06-13 11:50:312000browse

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

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

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


do.php 要执行的php,根据需要写不同内容便可。
<br /><?php<br />$ret = array();<br />$ret['success'] = 1;<br />$ret['msg'] = '调用php成功';<br />header('content-type:application/json');<br />echo json_encode($ret);<br />?><br />

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