dimanche 1 mars 2015

Call php script with ajax

I developped a web application (html,php5,javascript,ajax). I was using WAMPServer on windows and it was working right. I wanted to try it on ubuntu. I've installed LAMP and I put my project in /var/www/html after giving permissions I could run it on my browser. but sending data using ajax to a php script is not working and I don't know what is the problem. Can anyone help? even this simple example is not working :



<html>
<head>
<script src="/assets/jquery1.11.2.js"></script>
</head>
<body>
<button onclick="duplicate()"/>
<script>
function duplicate()
{
var action = "CreationBoard";
$.ajax({
type : "POST",
url : "file.php",
data : { action : action }
});
}
</script>
</body>


and this is my file.php :



<?php
$res = $_POST['action'];
file_put_contents("result.txt",$res);
?>


When the button is pressed a file named result.txt should be created, but it's not ... I saw many posts about this, this is how it should be done (I think), please tell me what's wrong .. i'm not used to work with Ubuntu. This example is working on Windows





Aucun commentaire:

Enregistrer un commentaire