Site icon Hip-Hop Website Design and Development

Ajax not working to insert, question and outcome knowledge

On my website, via a kind I ship/register similar data in database, do a SELECT/question and return it! Return the final desk saved in database, simply that consumer simply entered on the shape (together with some extra data coming from the database).

How I need to show these values coming from databse in a modal bootstrap it is necessary that the web page does not give the refresh. For this, I inserted the AJAX as follows:

$(doc).prepared(perform(){
      $('#enviar').click on(perform(){
          $.ajax({
          //CAAL  AJAX IN WORDPRESS 
          url: 'wp-admin/admin-ajax.php',
          kind: 'POST',              
          //INSERT, QUERY AND DISPLAYS TO USER      
          knowledge: 'motion=prancha',                  
          error: perform(){
              alert('ERRO!!!');
          },
          //IF OK, DISPLAYS TO USER IN DIV "RESULT"
          success: perform(knowledge){
              $('#outcome').html(knowledge);
          }               
      });
    });
    });

MY FUNCTIONS.PHP:

perform prancha(){
  header('Content material-Kind: textual content/html; charset=utf-8');

  embrace "../../../wp-config.php";


      /* DECLARING THE VARIABLES  */
  $nome = "";
  $e mail = "";
  $estilo = "";
  $experiencia = "";
  $altura = "";
  $peso = "";

  // VALIDATION
  if(!empty($_POST)){     
     $nome = $_POST['nome'];
     $e mail = $_POST['email'];
     $estilo = $_POST['estilo'];
     $experiencia = $_POST['experiencia'];
     $altura = $_POST['altura'];
     $peso = $_POST['peso'];

     cadastra_user($nome, $e mail, $estilo, $experiencia, $altura, $peso);
 }


  //INSERT IN DATABASE NAME, EMAIL, ESTILE, EXPERIENCE, HEIGHT AND WEIGHT
perform cadastra_user($nome, $e mail, $estilo, $experiencia, $altura, $peso){          
    world $wpdb;

    $desk = 'consumer';

    $knowledge = array(      
      'nome' => $nome,
      'e mail' => $e mail,
      'estilo' => $estilo,
      'exp' => $experiencia,
      'altura' => $altura,
      'peso' => $peso,
    );

    $up to date = $wpdb->insert( $desk, $knowledge );

    if ( ! $up to date ) {
      $wpdb->print_error();
    }    
}   

//CONECT WITH DATABASE TO DO THE SELECT
embrace "db.php";

  perform BuscaAlgo($conexao){

  // QUERY + INNER JOIN IN DATABASE
 $question = "SELECT  USU.usuario,
                   USU.nome,
                   USU.exp,
                   USU.altura,
                   USU.peso,
                   PRAN.exp_ref,
                   PRAN.altura_ref,
                   PRAN.peso_ref,
                   PRAN.tipo_prancha,
                   PRAN.tamanho_prancha, 
                   PRAN.meio_prancha, 
                   PRAN.litragem_prancha       
                    FROM DADOS_USUARIO AS USU 
                         INNER JOIN PRANCHA AS PRAN
                             on USU.exp = PRAN.exp_ref
                              WHERE USU.altura = PRAN.altura_ref
                                AND USU.peso = PRAN.peso_ref
                                  ORDER BY USU.usuario DESC LIMIT 1";



  $resultado = mysqli_query($conexao,$question);

  $retorno = array();

  whereas($experiencia = mysqli_fetch_assoc($resultado)){
    $retorno[] = $experiencia;
  }

 return $resultado;
}


//DISPLAYS THE QUERY TO USER      
$resultado = array();
$resultado = BuscaAlgo($conexao);

foreach($resultado as $valor){
    echo $valor["usuario"]; print(".  .  .  ."); 
    echo $valor["nome"]; print(".  .  .  ."); 
    echo $valor["exp"]; print(".  .  .  ."); 
    echo $valor["altura"]; print(".  .  .  ."); 
    echo $valor["peso"]; print(".  .  .  ."); 
    print("///////");
    echo $valor["tipo_prancha"]; print(".  .  .  ."); 
    echo $valor["tamanho_prancha"]; print(".  .  .  ."); 
    echo $valor["meio_prancha"]; print(".  .  .  ."); 
    echo $valor["litragem_prancha"];  
}  


    die(); //END THE EXECUTION
}
//ADD THE AJAX HOOKS IN WORDPRESS
add_action('wp_ajax_prancha', 'prancha');
add_action('wp_ajax_nopriv_prancha', 'prancha');

The code is commenting, mainly I did:

AJAX:

FUNCTIONS: I make the license plate in database, do the question and print with the echo.

The AJAX is returning me the error message. It is the error of AJAX itself. The sector error: perform(){ alert('ERRO!!!');},

How can I resolve this?
What am I doing improper?

Note1: Once I insert the code that’s in my ‘features, the license plate, the question and theecho’ to shows in a direct means, in my footer.php, it really works. Subsequently, we are able to perceive that the error will not be even within the code of insert,question or shows.

NOTE 2: I need to show the return of database inside a modal boostrap. At first I am simply displaying on the display, to examine that the whole lot is OK. After that I’ll analysis on easy methods to put these knowledge into the modal, though not the principle topic of the put up, solutions for the way to do that are additionally welcome.