Sunday 28 January 2018

PHP Tutorial : Include Page On Button Click Without Refreshing Main Page | Dynamic Page Loading

Remember that this technique has 1 drawback, watch the video above to understand it. Comment down if you have any questions.
Source Code :-
dynamic.php
<head>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){ $("b").click(function()
    {
    document.getElementById("include").innerHTML = "<?php echo include('Second.php');
?> "; });
    $(document).on("click", "a.remove" , function()
    { $(this).parent().remove(); }); });
</script>
</head>
<body>
<b><input type='submit' value='Add second page'></b>
<div id='include'></div>
</body>

Second.php
<?php
echo 'This is second page';
?>

1 comment:

  1. This works for continuous stings but when there are line breaks this error is received: "Uncaught SyntaxError: "" string literal contains an unescaped line break". I tried escaping \r\n and just \n. Neither worked. I can concantenate the content into one formatted string, but is there a way to use line breaks? Thanks!

    ReplyDelete