在javascript代码中运行一个phpcode

时间:2018-02-13 13:30:49

标签: javascript php html

需要帮助才能添加以下php代码

<?php 
//while($res = mysql_fetch_array($result)) { // mysql_fetch_array is deprecated, we need to use mysqli_fetch_array 
while($res = mysqli_fetch_array($result)) {         
    echo "<div><a href=\"".$res['weblink']."\">".$res['weblink']."</a></div>";
    echo "<td>".$res['webtitle']."</div>";
    echo "<div>".$res['webdomain']."</div>";    
}
?>

到这个javascript文件

(function() {
    document.writeln('\
        <div style="display:none;">\
            <table width="100%"><tr><td>\
                <div>\
                    <div>\
                        <div>\
                            <a href="https://yahoo.com/emails" target="_blank">yahoo emails</a>\
                        </div>\
                        <div>\
                            <span>yahoo.com</span>\
                        </div>\
                    </div>\
                </div>\
            </td></tr></table>\
        </div>\
    ');     
});

以上javascript代码将作为php文件运行,我将其作为javascript包含在html页面中

document.write('<scr'+'ipt type="text/javascript" src="example.php"></scr'+'ipt>');

如何在javascript代码中替换html表,以便在php中工作。

任何帮助? 问候

1 个答案:

答案 0 :(得分:0)

你必须在文档就绪函数的ajax请求中调用api。您得到的回复已添加到表格中。以下是示例。

data_new.forEach(function(arr){
                $('#book_table tbody').append('<tr>' +
                    '<td>'+arr['BOOKNUMBER']+'</td>' +
                    '<td>'+arr['TITLE']+'</td>' +
                    '<td>'+arr['STATUS']+'</td>' +btn_data+'</tr>');
            });
相关问题