首页 > 解决方案 > 我用 javascript 创建了一个表格,但表格的内容是在 php.ini 中。如果无法在 js 中运行 php,如何在表格中插入此内容?

问题描述

我用 javascript 创建了一个表格,但表格的内容是在 php.ini 中。如果无法在 js 中运行 php,如何在表格中插入此内容?

<script> 

  

    NROW = 10;
    
    body = document.body;
    
    div = document.createElement('div');
    body.appendChild(div);

    table = document.createElement('table'); table.setAttribute('border','1');
    div.appendChild(table);
    
    
    for(j=0;j<NROW;j++){
        tr = document.createElement('tr');
        table.appendChild(tr);

            
            td = document.createElement('td');
            tr.appendChild(td);
      /*HERE IS THE PROBLEM*/
      text = createTextNode(<?php echo 'test'?>);
      
            

            td = document.createElement('td');
            tr.appendChild(td);
            

        
    }



</script>

```fdsklk`

标签: javascriptphphtml

解决方案


只是为了记录和帮助别人。遵循上面 Kinglish 的帮助。

我用这个:

<!DOCTYPE html>
<html>
<body>

<div id="demo">
<h1>The XMLHttpRequest Object</h1>
<button type="button" onclick="loadDoc()">Change Content</button>
</div>

<script>
function loadDoc() {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      document.getElementById("demo").innerHTML =
      this.responseText;
    }
  };
  xhttp.open("GET", "ajax_info.txt", true);
  xhttp.send();
}
</script>

</body>
</html>


推荐阅读