lundi 2 mars 2015

Get data from php script using Ajax

I am trying to use some data calculated with a php script in javascript, this is my code :



<html>
<head>

<script src="http://ift.tt/1dW8QIk"></script>
</head>
<body>
<button onclick="duplicate()"> button send</button>


<script>
function duplicate()
{
var action = "CreationBoard";
alert(action);
$.ajax({
type : "POST",
url : "file.php",
data : { action : action },
success: function(output) {
alert(output);
}
});
}
</script>
</body>
</html>


So I'm calling file.php to calculate my data :



<?php
if(isset($_POST['action']))
{
$return = some_function($_POST['action']);
}
?>


I need to use $return in javascript, how to do that ?? I've seen many examples, but they only show how to send data with Ajax to php, not from php to ajax. How should I do that ??





Aucun commentaire:

Enregistrer un commentaire