-1

need help in adding the following php code

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

to this javascript file

(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>\
    ');     
});

the above javascript code will run as php file and i will include it in html page as a javascript

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

how can i replace the html table in javascript code to work as it be in php .

any help ? regards

Banana
  • 2,435
  • 7
  • 34
  • 60
  • 1
    Is there any reason that file needs to be a javascript file? It looks like you are just using javascript to display some html. You should just be able to use one php file for this. – StealthSpoder Feb 13 '18 at 13:38

1 Answers1

0

You have to call api in ajax request on document ready function. The response you get have append in the table. Below is the example.

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>');
            });
Ramesh
  • 32
  • 1
  • 7