2012-02-16 2 views
0

html 요소에 대한 액세스와 관련하여 질문이 있습니다.PHP에서 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? 
} 

이 흐름 가능한 사람인가? 왜냐하면 내가 할 수 없어.

도움말 ..

감사합니다,

+4

그것은 훨씬 쉽게 수 있습니다 AJAX로'file1.php'에서 필요한 모든 값을'file3.php'에 넘기는다면 –

+0

@KemalFadillah 당신은 file2.js에서 table 객체를 얻고 file3.php로 넘겨주는 것을 의미합니까? – tinks

+0

실제로 JavaScript로 DOM을 탐색하고 필요한 모든 값을 테이블에서 가져 와서 AJAX를 통해 보냈습니다. 나는 당신이 찾고있는 것이 데이터와 테이블 자체가 아니라는 것을 확신한다. –

답변

1

비슷한 동작을 얻을 수있는 가장 쉬운 방법은 자신의 파일

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

감사합니다 @ Gottox 어떻게 $ 테이블의 세포에 액세스 할 수 있습니까? 그 세포에 읽은 값을 넣어야합니다. – tinks

+0

나는이 하나의 IL을 시도하지만, 여기에 테이블의 셀에 접근하는 방법을 모르겠다. – tinks

+0

은 테이블의 셀에 접근 할 수 없다. 그 이유는 다음과 같다. ( – tinks

0

예 가능합니다. 난 당신이 여기 file1.php 콘텐츠에 액세스 할 수 있도록

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; 
} 

을 생각하지 않는다! (아약스 데이터로 전달되지 않은 경우)

+0

내 파일이 너무 커서 .. 한 줄에 줄을 읽었습니다. 줄을 읽은 후 돌아 오면 모든 것을 읽을 수 없습니다. – tinks