Home  >  Article  >  Backend Development  >  怎么点击按钮执行php函数

怎么点击按钮执行php函数

WBOY
WBOYOriginal
2016-06-13 12:02:574738browse

如何点击按钮执行php函数
大家好,我目前的需求是点击一个按钮,然后把当前页的一个列表用fpdf输出为pdf文件,请问要怎么做呢?
------解决方案--------------------
表单提交、js跳转、ajax
------解决方案--------------------
1.使用ajax,執行php文件
2.php文件中,創建pdf文件,并返回pdf路徑
3.顯示pdf文件路徑

a.php

<br /><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><br /><html><br /> <head><br />  <title> New Document </title><br />  <script src="//code.jquery.com/jquery-1.11.0.min.js"></script><br /> </head><br /><br /> <body><br />  <script type="text/javascript"><br />  function dophp(){<br />	  var url = 'http://localhost/b.php';<br />	  $.getJSON(url, function(data){<br />		document.getElementById('dl').innerHTML = data.url;<br />	  });<br />  }<br />  </script><br /><br />  <input type="button" value="exec php" onclick="dophp()"><br />  <div id="dl"></div><br /><br /> </body><br /></html><br />


b.php
<br /><?php<br />$ret = array('url' => 'http://localhost/1.pdf');<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