Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my PHP not activate when I embed it with JavaScript?

I embedded a PHP file with JavaScript but the PHP didn't work. Here's what I did:

$.get("php/file.php");

In the PHP file:

<?php
    echo "Testing PHP File"
?>

I would really appreciate it if someone answered me!

like image 844
Maytha8 Avatar asked Jul 20 '26 15:07

Maytha8


1 Answers

you should used $.get() like this

$.get('php/file.php', function(data) {
                alert(data);//here is your "Testing PHP File" data
            });

Make sure: this will work on any event like click or other (i suppose you know about server side and client side)

$('.class_name').click(function() {
            $.get('php/file.php', function(data) {
                    alert(data);
                });
        });
like image 123
Bilal Ahmed Avatar answered Jul 23 '26 07:07

Bilal Ahmed