2013-08-22 2 views
-1

저는 AJAX를 처음 접했고 PHP에서 html 표를 표시해야합니다. 생성 버튼을 누르면 아래 표가 표시됩니다. xmlhttp.onreadystatechange=function() 부분에phtml과 ajax를 사용하여 html로 표를 표시합니다.

function showHint() 
{ 
var xmlhttp; 
if (window.XMLHttpRequest) 
    {// code for IE7+, Firefox, Chrome, Opera, Safari 
    xmlhttp=new XMLHttpRequest(); 
    } 
else 
    {// code for IE6, IE5 
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
    } 
xmlhttp.onreadystatechange=function() 
    { 
    if (xmlhttp.readyState==4 && xmlhttp.status==200) 
    { 
    //what codes to put here when in terms of button. 
    } 
    } 
xmlhttp.open("GET","list.php", true); 
xmlhttp.send(); 
} 
</script> 
</head> 
<body> 
    <button onClick="showHint()">Generate</button> 
</body> 

진술해야한다 무엇 : 이 HTML 파일에 내 코드는? 사전에

<?php 
$a[]="James Burb"; 
$a[]="Melvin Chapman"; 
$a[]="Eric Chan"; 
$a[]="Aira Gomez"; 
echo "<table border=1>"; 
for($i=0; $i<count($a); $i++) 
{ 

echo "<tr>"; 
echo "<td>" .$hint=$a[$i]. "</td>"; 
echo "</tr>"; 

} 
echo "</table>"; 
?> 

감사 :

이 내 PHP 파일입니다.

답변

0

다음과 같이 일부 사업부에 테이블을 표시합니다 xmlhttp.responseText를 사용할 수 있습니다

xmlhttp.onreadystatechange=function() 
    { 
    if (xmlhttp.readyState==4 && xmlhttp.status==200) { 
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText; 
    } 
} 

그것은 사업부에 list.php에 의해 반환 된 테이블을 배치합니다.

+0

도움을 주셔서 감사합니다. 그것은 작동합니다. – WATTS

+0

친절하게 답변을 동의라고 표시하십시오. –

관련 문제