1
I have the following example:
My file HTML has this code snippet:
<script>
$( "form" ).submit(function( event ){
event.preventDefault();
$.ajax({
url : 'funcoes.php',//url para acessar o arquivo
data: {id : 10},//parametros para a funcao
type : 'post',//PROTOCOLO DE ENVIO PODE SER GET/POST
dataType : 'json',//TIPO DO RETORNO JSON/TEXTO
success : function(data){//DATA É O VALOR RETORNADO
alert(data.valor);//VALOR INDICE DO ARRAY/JSON
},
});
});
</script>
and I also have a file called php functions. with the following content:
<?php
function teste(){
echo json_encode(array('valor' => $_POST['id']));
}
function teste2(){
echo json_encode(array('valor' => $_POST['id']));
}
?>
What I’d like to know is: How do I access function teste1(or teste2)? What I have to pass as "parameter" in my HTML file so that it knows which of these two functions I want to execute ?
I advise to read a little about REST
– MarceloBoni
You can pass as a date, something like:
data: {id : 10, acao: "algumaCoisaQueDefineQualFuncaoVaiSerAcessada"}
E in the backend use aswitch case
to filter which function should be accessed when passed such action– MarceloBoni
I understood your idea, I will try to apply it and I return with the result, I thank also for the indication of reading on REST, giving a glance I saw that there are several things that fit my need.
– Lks