duanhui9840 2013-05-04 19:13
浏览 67

单击按钮运行php代码并回显结果

I want to implement this script: 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.

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?

  • 写回答

1条回答 默认 最新

  • 普通网友 2013-05-04 19:42
    关注

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

    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</>
    

    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>
    

    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

    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办