【问题标题】:PHP/Ajax/HTML/SSH - I do not understand why it does not workPHP/Ajax/HTML/SSH - 我不明白为什么它不起作用
【发布时间】:2019-06-09 13:54:22
【问题描述】:

我不明白问题出在哪里。如果有人有想法:(我必须从 ssh 服务器下载文件,但文件会根据用户的要求进行切换。我有一个用于 ssh 连接和下载的 PHP 文件。我正在使用 ajax,因为我有发送文件位置。

让我们看看代码:

HTML:

       <?php if ( !is_null($this->listdepotdrpadmin) ) { ?>
            <table id="supervisionResDepotDrp">
                <thead>
                    <tr>
                        <th class="center">EVT_ID</th>
                        <th class="center">EVT_DT</th>
                        <th class="center">EVT_NOMFIC</th>
                        <th class="center">EVT_STATUT</th>
                        <th class="center">EVT_TEXTE</th>
                        <th class="center">DOWNLOAD</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                     <!-- Le 7ème champ statut_depot n'est pas affiché, car il sert uniquement pour les RG
                      Il est redondantt avec le 6ème qui est sa traduction en langage humain -->
                      <?php foreach ($this->listdepotdrpadmin as $elem) :?>
                        <tr>
                            <td class="center"><?php print_r($elem['evt_id'])?></td>
                            <td class="center"><?php print_r($elem['evt_dt'])?></td>
                            <td id="afficher" class="center"><?php print_r($elem['evt_nomfic'])?></td>
                            <td class="center"><?php print_r($elem['evt_statut'])?></td>
                            <td class="center"><?php print_r($elem['evt_texte'])?></td>                
                            <!-- Si le champs evt_statut est remplis, affiche l'icone de telechargement -->  
                            <td class="center">
                                <?php if (isset($elem['evt_nomfic'])) : ?> 
                                    <img class='img-download' src='/img/download.png' id="js-download-file">
                                <?php endif;?>
                            </td>
                        </tr>
                        <span id="spnText"></span>
                       <?php endforeach; ?> 
                    </tr>
                </tbody>
            </table>
          <?php } ?>

PHP 文件:

public function ajaxdownloadfileAction() {
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender();

        $this->view->lib = $this->_labelsFile;

        $connection = ssh2_connect($this->_configFile->ftp->hostname, $this->_configFile->ftp->port);
        if ($connection) {
            $login = ssh2_auth_password($connection, $this->_configFile->ftp->login, $this->_configFile->ftp->password);
            if ($login) {
                $content = true;
                if ($content) {
                    $fileName = $this->_getParam('fileName');  
                    $local = ' C:\Users\nboulein\Desktop\test\ ';
                    ssh2_scp_recv($connection,$fileName,$local);

            }
            $connection = null; unset($connection);
        }
     }

     $result['status'] = 'OK';
     $result['message'] = 'LE ficheir a bien ete telecharger';

     echo json_encode($result);
}

Ajax 文件:

// Gestion du bouton de téléchargement du fichier
$('#resultatsRecherche').on('click','#js-download-file',function(){
    $('#js-download-file').css("cursor","pointer" );
    var currow = $(this).closest('tr');
    var fileName = currow.find('td:eq(2)').text();
    alert(fileName);
    $.ajax({
        type : 'POST',
        url : '/supervision/admin/ajaxdownloadfile',
        async : true,
        data : {
            fileName : fileName
        },
        success : function(result) {
           var vResult = jQuery.parseJSON(result);
           if(vResult.status == 'OK'){
               alert(vResult.message);
           }
        }  
    });
});

在我的网页上什么都没有发生,当我打开控制台时,会出现这样的情况:

未捕获的类型错误:$(...).on 不是 HTMLDocument 中的函数。
(admin.js:224) 在 Object.resolveWith (jquery-1.5.1.min.js:16)
在 Function.ready (jquery-1.5.1.min.js:16) 在 HTMLDocument.A (jquery-1.5.1.min.js:16)

我尝试进入我的 AJAX 网页,结果如下:

警告:ssh2_scp_recv() [function.ssh2-scp-recv]:无法接收远程文件
D:\www\SAGAPEC\application\modules\supervision\controllers\AdminController.php
在第 383 行 {"status":"OK","message":"LE ficheir a bien ete telecharger"}

【问题讨论】:

  • “不起作用”是没有描述的。 How to Ask你观察到了什么?服务器和浏览器的错误日志。

标签: php ajax ssh html-table


【解决方案1】:

$(...).on 不是函数

jquery-1.5.1.min.js

on 方法是在 jQuery 1.7 中引入的。

您的 jQuery 版本太旧了。它是从 2011 年开始的!

升级到更新版本的 jQuery。

请注意,jQuery 的所有 1.x 和 2.x 版本都已过时,不再接收安全更新。

使用 jQuery 3.3。

【讨论】:

    猜你喜欢
    • 2021-07-10
    • 2014-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-23
    • 2021-10-07
    相关资源
    最近更新 更多