I have a website hosted on server, now what I want is to run a .php script (Also located on the same server) when someone presses the submit button in the website.
Following is the ajax code
$.ajax({url: "/test.php",
success: function(response){
console.log("Success",response);
}
});
My test.php consists of
<?php
//exec('sudo -u www-data python /var/www/html/test.py');
echo "PHP Script Ran";
mkdir("/var/www/html/test", 0700);
?>
When I navigate to ip_address/test.php, the echo
message is displayed correctly but the mkdir
command doesn't seem to be executed as there is no folder created in my server's directory.
Also I want to know, how can I run this test.php script when someone presses the submit button in my website.
The Javascript code is
var $ = jQuery;
var timestamp = Number(new Date());
var form = document.querySelector("form");
var database = firebase.database();
form.addEventListener("submit", function(event) {
var ary = $(form).serializeArray();
var obj = {};
for (var a = 0; a < ary.length; a++) obj[ary[a].name] = ary[a].value;
console.log("JSON",obj);
firebase.database().ref('users/' + timestamp).set(obj);
database.ref('users/' + timestamp).once('value').then(function(snapshot) {
console.log("Received value",snapshot.val());
$.ajax({
url: "/test.php",
success: function(response){
console.log("Success",response);
}
});
});
});
Any help on this would be much appreciated. Thanks