点击按钮运行PHP code和回声效果 [英] click on the button to run php code and echo result

查看:171
本文介绍了点击按钮运行PHP code和回声效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要执行这个脚本:的http://www.daniloaz.com/en/560/programming/backup-de-bases-de-datos-mysql-con-php/

在我的网站备份所有的数据库在这一天结束。

on my website to backup all the database at the end of the day.

我想知道是否有可能对我来说,把一个按钮,点击并运行该脚本和回声状态后完成而无需刷新页面或者带我去一个新的页面。

May I know is it possible for me to put a button to click and run the script and echo the status after it finish without refreshing the page or bring me to a new page.

由于此刻的我每天需要去的链接:www.example.com/backup.php做日常备份,我想这缓解我的工作:)

as at the moment i everyday need to go to the link: www.example.com/backup.php to do daily backup, I want this to ease my job :)

任何想法如何做到这一点?

any idea how to do this?

推荐答案

按钮的是什么类型的?如果HTML是很容易

what type of button? if html yes it's easy

对你,象这样一个div沿着什么都想要网页上的按钮:

have a button on what ever page you want along with a div like so:

<input type="button" name="perform_backup"  onclick="do_backup()"><div id="results"> No backup has been performed yet</>

再有它调用备份PHP脚本这样一个JavaScript

then have a javascript which calls your backup php script like this

<script>  
 function do_backup(){
   var xhReq = new XMLHttpRequest();
   var request = "http://www.example.com/backup.php " // this will prepare a request to your server
   xhReq.open("GET", request, false);  // send a request
   xhReq.send(null);
   document.getElementsByID("results").innerHTML=xhReq.responseText  /// this will display results

   }
</script>

然后我会修改服务器上的脚本给更多然后一个布尔变量但是这取决于你。但无论你选择它会在&LT可以看出; DIV ID =结果&GT; ,而无需加载了新的一页......这种方法被称为AJAX为未来的问题

then I would modify the script on your server to give more then a boolean variable but that's up to you. But whatever you choose it will be seen inside <div id="results"> , without loading a new page... This method is called AJAX for future questions

这篇关于点击按钮运行PHP code和回声效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆