如何使用Ajax和OOP php从数据库中检索数据

时间:2017-07-01 12:20:48

标签: php jquery ajax oop

我将用ajax和php开发网页。但是我的get_data_in_table函数存在问题。它将在表结构中显示数据。但是当我运行此代码时它显示错误。其他人工作正常。它在while循环中显示错误。但我无法找到任何问题。

     <script src="https://cdnjs.cloudflare.com/ajax/libs/vue-resource/1.3.4/vue-resource.js" type="text/javascript"> </script>
    <script src ="https://cdnjs.cloudflare.com/ajax/libs/vue/2.3.0/vue.js"></script>
    <script>

    Vue.component('record', {
    template: '#record-template',


      data: function () {
            return {
                isRecording: false,
                audioRecorder: null,
                recordingData: [],
                dataUrl: ''
            };
        },
    methods:
        {
          //method to start and stop the recording process
            toggleRecording: function() {
              var that = this;
              this.isRecording = !this.isRecording;

              if (this.isRecording) {
                  navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
                  navigator.getUserMedia({
                          audio: true,
                          video: false
                      }, function(stream) {
                          that.stream = stream;
                          that.audioRecorder = new MediaRecorder(stream, {
                              mimeType: 'audio/webm;codecs=opus',
                              audioBitsPerSecond : 96000
                          });

                          that.audioRecorder.start();

                          console.log('Media recorder started');

                      }, function(error) {
                          alert(JSON.stringify(	error));
                  });
              }
              else {
                  this.audioRecorder.stop();
              }

                  this.audioRecorder.ondataavailable = function(event) {
                    that.recordingData.push(event.data);

                  }
                  this.audioRecorder.onstop = function(event) {
                    console.log('Data available after MediaRecorder.stop() called');
                    // var audio = document.createElement('audio');
                    // audio.controls = true;

                    var blob = new Blob(that.recordingData, { type: 'audio/ogg'});
                    that.dataUrl = window.URL.createObjectURL(blob);
                    // audio.src = dataUrl;
                    console.log("recorder stopped");
                  }

            },

            //method to remove a recording that was saved previously
            removeRecording: function() {
              this.isRecording = false;
              this.recordingData = [];
              this.dataUrl = '';

            },
            //method to  start and stop the playback process
            togglePlay: function() {
              var audioElement = document.getElementById("audio");
              if (audioElement.paused === false) {
                  audioElement.pause();
              } else {
                  audioElement.play();
              }
              // var handleSuccess = function(stream) {
                // if (window.URL) {
                //   audioElement.src = window.URL.createObjectURL(stream);
                // } else {
                //   audioElement.src = stream;
                // }




            },
            //method to submit the recording to the API using  vue-resource
            submitRecording: function() {
            }
        },


    });


     new Vue({
        el: '#app'


    });

    </script>

1 个答案:

答案 0 :(得分:2)

我想我找到了它:

  class get_data()

    {
     public function get_data_in_table($query){
            $output='';
            $result=  $this->Getdata($query);
            $output.='
                    <table class="table table-bordered table-striped">
                    <tr>
                    <th>Countty</th>
                    <th>Airline Name</th>
                    <th>Arrival Time</th>
                    <th>Status</th>
                    <th>Comment</th>


    </tr>';
            while($row= mysqli_fetch_array($result)){
                $output .='

                        <tr>
    <td>'.$row->country.'</td>
    <td>'.$row->air_line.'</td>
        <td>'.$row->arrival_time.'</td>
          <td>'.$row->status.'</td>
              <td>'.$row->comment.'</td>


    </tr>';


            }
            $output.='</table>';
            return $output;
                    }
} // This was missing
    ?>