10
I’m having difficulty requesting a PHP function via Ajax
AJAX code:
$.ajax({
   url:   'geraSenhaProvisoria.php',
   type:  'POST',
   cache: false,
   data:  {geraSenha(6, true, true, true)},
   error: function() {
         alert('Erro ao tentar ação!');
   },
   success: function( texto ) { 
         $("#senha_provisoria").val( texto );
         $("#senha_provisoria").removeAttr("disabled");
   },
   beforeSend: function() {
   }
});
geraSenhaProvisoria.php
 function geraSenha($tamanho = 6, $maiusculas = true, $numeros = true, $simbolos = false){
    $letrasMinuscula = "abcdefghijklmnopqrstuvwxyz";
    $letrasMaiuscula = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $numero          = "1234567890";
    $simbolo         = "!@#$%*-";
    $retorno         = "";
    $caracteres      = "";
    $caracteres .= $letrasMinuscula;
    if ($maiusculas){ $caracteres .= $letrasMaiuscula; }
    if ($numeros){    $caracteres .= $numero; }
    if ($simbolos){   $caracteres .= $simbolo; }
    $len = strlen($caracteres);
    for ($n = 1; $n <= $tamanho; $n++) {
    $rand = mt_rand(1, $len);
    $retorno .= $caracteres[$rand-1];
    }
    return $retorno;
}
I adapted here in my code and worked perfectly, thanks help! vlw.
– Bruno Duarte
how did yours turn out please?
– Marcelo Augusto Colombo