Доступ к HTML-таблицам в PHP - PullRequest
       0

Доступ к HTML-таблицам в PHP

0 голосов
/ 16 февраля 2012

У меня вопрос относительно доступа к элементам html.

File1.PHP

<table id="tableID">
<tr>
    <td>&nbsp
    </td>
</tr>
</table>
<input type=button onclick=changeValue();>
<script type="text/javascript" src="file2.JS"></script>

File2.JS

function changeValue(){ 
//HAS AJAX OBJECT THAT CALLS file3.php to read a file
ajax.doPost("file3.php", callback); }

File3.php

  function fileRead(){
   ...
   $line = fgets($file_handle);
   ///After reading the lines of the file in File3.php 
   ///I want to output it in the table in File1.PHP without returning 
   ///it as xmlResponse to File2.JS
   ///Is it possible to acces the table in File1.PHP here?
 }

Возможен ли этот поток?Потому что я не могу заставить его работать.

Помощь ..

Ответы [ 2 ]

1 голос
/ 16 февраля 2012

Самый простой способ получить похожее поведение - поместить таблицу в отдельный файл

Table.php

<?php
  ob_start();
?>
<table id="tableID">
  <tr>
    <td>&nbsp</td>
  </tr>
</table>
<?php
  // Save content of this page in a variable
  $table = ob_get_contents();
  ob_end_clean();
?>

File1.PHP

<?php
  include "table.php";
  // Access $table defined in table.php
  echo $table;
?>
<input type=button onclick=changeValue();>
<script type="text/javascript" src="file2.JS"></script>

File3.php

  function fileRead(){
   // Access $table defined in table.php
   echo $table;
 }
0 голосов
/ 16 февраля 2012

да, это возможно.

function changeValue(){ 
$.ajax({
                type: "POST",
                data:"filenametoread=filename",
                url:"path to file3.php
                success: function(msg){
                   $("#tableID").html(msg);  
                }
            });
}

file3.php

if(isset($_REQUEST['filenametoread']){
      return fileRead($_REQUEST['filenametoread']);
}
function fileRead($filename){
   ...
   $line = fgets($file_handle);
   return $line;
 }

Не думаю, что вы можете получить доступ к содержимому file1.php здесь! (Если не переданы как данные ajax)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...