I have this code

<a href="images/xxx.jpg" download onclick="isEmail()">Click Me</a> <script type="text/javascript"> function isEmail() { $(document).ready(function(){ $.ajax({ type: 'POST', url: 'script.php', success: function(data) { document.write("data"); } }); }); } </script> 

But the problem is that when you click on the tag, everything disappears except for the script.php itself.

And I need that when clicking on the tag (a) the php code is displayed after javascript

Like so

 <script> document.write('<?php echo "<h3>tre</h3>";?>'); </script> <h3>tre</h3> 

    1 answer 1

     $(document).ready(function() { $(".clickme").click(function(e) { e.preventDefault(); $.ajax({ type: 'POST', url: 'script.php', success: function(data) { $("body").append(data); }, error: function(xhr, status, error) { $("body").append($("<h3></h3>").text("ERROR: " + status)); } }); }); }); 
     <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <a href="#" class="clickme">Click Me</a> 

    • Thank you so much - zeni1agent