首页 > 解决方案 > 如何在 PHP 文件中调用 JS 函数

问题描述

我有一个项目,我可以在网站上上传特定的 excel 文件。excel 文件在网站上显示为 html 表格。表格下方是一个按钮,用于将表格上传到数据库中。因此,我将表格单元格保存在一个数组中(在 JS 函数中)。最后,我将数组传递给第二个 php 文件,在那里我将数组数据上传到数据库中。在上次上传时,我想显示一个弹出窗口。我有这些文件:

上传.php

if (isset($_FILES['file']) && !empty($_FILES['file'])) {
    //show excel file as table on website
    <form  action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data">
       <button id="exBtnHoch" name="exBtnHoch" onclick="saveInArray()" type="button"  class="btn btn-success btn-block">Excel-Datei hochladen</button>
       </br></br></br></br></br></br>  
    </form>
}

excelEinlesen.php

include "pop_up.php";

if(isset($_POST['daten'])){    //checks if array is passed
    //if successfull then do something like:
    echo '<script type="text/javascript">showPOP_UP();</script>';
}
//EDIT
function a (){}      //they are called in the if-part

function b (){}

编辑:pop_up.php:HTML代码

<!doctype html>
<html lang="de">
    <head>
        <!-- Required meta tags -->
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

        <!-- Bootstrap CSS -->
        <link rel="stylesheet" href="../css/bootstrap.min.css">
        <script type="text/javascript" src="js/excelEinlesen.js"></script>
    </head>
    <body>
    <div class="modal fade" id="pop_upHochgeladen" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="false">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Speichern</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
            <div class="modal-body">
                Die Daten des Mitarbeiters wurden erfolgreich in die Datenbank geschrieben.
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-warning" onClick="geheZuHome()">Zurück zur Startseite</button>
                <button type="button" class="btn btn-warning" onClick="window.location.href=window.location.href">Weitere Datei hochladen</button>
            </div>
            </div>
        </div>
    </div>
    </body>
</html>

excelEinlesen.js

function saveInArray(){
    //save table cells in array
    //at the end pass array to excelEinlesen.php
}

function showPOP_UP(){
    $('#pop_up').modal('show');   
}

我试图回应它并搜索整个互联网,但没有任何令人满意的解决方案。首先在 upload.php 中有第二个 onclick 并且它有效,但我想在没有 onclick 的特定情况下调用 JS 函数。

我不知道这是否有问题,但我的文件有不同的文件夹:“js”和“php”。

标签: javascriptphphtml

解决方案


推荐阅读