dstnlhhv791576 2019-06-04 08:08
浏览 41

使用ajax同时运行2个codeigniter函数

<!--------TEST CONTROLLER-------------->

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class test extends CI_Controller{

    public function testp()
    {
        $this->load->view('admin/user/test');
    }

    public function convo()
    {
        $this->ConverterOperationsHandler->convo();
    }

    public function testprogress()
    {
        $this->ConverterOperationsHandler->testprogress();
    }

    public function tests()
    {
        $tet='a1a67b265388c6d19d4b62e5b1da6740de0bf055';
        $tet2='18';
        $tet3='3';
        $this->ConverterOperationsHandler->downloadFileRequiredMp3($tet,$tet2,$tet3);
    }
}

<!--------------------MODEL----------------------------->

public function convo()
    {
        $arrDownloadInfo['url']       = 'https://www.youtube.com/watch?v=cg3myULHqiE';
        $arrDownloadInfo['format_id'] = '249';
        $arrDownloadInfo['Filename']  = 'test123456';

        $quality = '128';
        $cmd = 'C:/Users/Ganeendra/Desktop/youtube/ffmpeg.exe'.' -i '.'assets/temp/'.$arrDownloadInfo['Filename'].'.webm -vol '.'2560'.' -y -acodec libmp3lame -ab '.$quality.'k '.'assets/downloads/convo_123.mp3' . ' 2> assets/logs/' . '123' . '.txt';

        exec($cmd);

        exit(json_encode('true'));
    }

  <!------------------------------------------------>
  public function testprogress()
    {
        $content = @file_get_contents('assets/logs/123.txt');

    if($content){
    //get duration of source
    preg_match("/Duration: (.*?), start:/", $content, $matches);

    $rawDuration = $matches[1];

    //rawDuration is in 00:00:00.00 format. This converts it to seconds.
    $ar = array_reverse(explode(":", $rawDuration));
    $duration = floatval($ar[0]);
    if (!empty($ar[1])) $duration += intval($ar[1]) * 60;
    if (!empty($ar[2])) $duration += intval($ar[2]) * 60 * 60;

    exit(json_encode($progress));
    }
    }

  <!---------------VIEW----------------------->

  echo '<style> #myProgress {
  width: 100%;
  background-color: grey;
}

#myBar {
  width: 1%;
  height: 30px;
  background-color: green;
} </style>';


echo '<div id="myProgress">
  <div id="myBar">1%</div>
</div>';



  echo'<script src="http://localhost/search/assets/js/jquery-3.2.1.min.js"></script>';

  echo '<script type="text/javascript"> move(); 
    function move() {
  $.getJSON("http://localhost/search/test/convo",function(data){});

  var elem = document.getElementById("myBar");  
  var width = 1;
  var id = setInterval(frame, 10);
  function frame() {
    $.getJSON("http://localhost/search/test/testprogress",function(results){
    width=results;
    if (width > 100) {
      clearInterval(id);
    }
    else if(width==100)
    {
      elem.style.width = width + "%"; 
      elem.innerHTML = width * 1  + "%";
    } 
    else 
    {
      width++; 
      elem.style.width = width + "%"; 
      elem.innerHTML = width * 1  + "%";
    }
    });
  }

}

</script>';

I have an issue with codeigniter. i have tried to call 2 functions simultaneously using ajax but no luck, Problem is when i do call my 1st function , 2nd function will be always pending until the first function completes the process.

so any suggestions?

my current code as follows.

So basically what i'm trying to do is when i call testp() function it will load the view with progress bar then by move() js function will call convo() function via ajax to start the conversion process and update the 123.txt file then within the move() js function i will be calling another ajax call to retrieve current conversion progress from 123.txt file(testprogress()). and i have set interval within the frame function in order to get current progress from 123.txt file. but the issue is as i mentioned earlier even though i call testprogress() function it won't run until convo() function finishes it's process. which makes my progress bar getting updated 100% at once.

and also please note if i used just php without using codeigniter it works perfectly.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 关于大棚监测的pcb板设计
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题