Request via AJAX with jQuery.
We’re accessing a file http://exemplo.com/funcoes.php
, assuming it is in the same directory, it is possible to access links. A very simple example, this is the HTML file:
<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 the file funcoes.php
<?php
//funcao retornando um json
function teste(){
echo json_encode(array('valor' => $_POST['id']));
}
//executando a funcao
teste();
?>
Take a look here: http://answall.com/questions/6626/howto create a-site-sem-reload
– Sergio
Forget it it is very bad to validate via PHP. Front-end validation depends on the user. PHP validation is not susceptible to failure. If the user disables javascript or causes its validation function to always return true, its validation is over.
– Wallace Maxters