insert data via javascript

0

I have a table with the INCLUDE button containing the following code:

<td align="center"><input type="button" class="add" onclick="add_row(<?php echo($id_usuario); ?>, 0);" value="INCLUIR"></td>

The table.js file contains the function add_row () with the following code:

function add_row(pid_usuario,pdia_da_semana)
{
    var inicio=document.getElementById("inicio").value; 
    var fim=document.getElementById("fim").value;   
    window.alert('ENTROU'); 

    //INCLUIR_REGISTRO(pid_usuario, pdia_da_semana, inicio, fim);

    var table=document.getElementById("data_table");
    var table_len=(table.rows.length)-1;
    var row = table.insertRow(table_len).outerHTML="<tr id='row"+table_len+"'><td id='inicio_row"+table_len+"'>"+inicio+"</td><td id='fim_row"+table_len+"'>"+fim+"</td><td align='center'> <input type='button' value='EXCLUIR' class='delete' onclick='delete_row("+table_len+")'></td></tr>";

    document.getElementById("inicio").value=""; 
    document.getElementById("fim").value="";

}

Basically what I do with the include button is to add a new row to the table. So I thought .. Since I'm adding the line because it does not include the record at this point. Home Ai that comes with the lack of experience .. I have no idea how to do the INCLUIR_REGISTRO() function.

Should any of the more experienced colleagues help me?

    
asked by anonymous 03.08.2017 / 19:50

1 answer

0

Good morning, everyone ...
I leave here the solution to the problem proposed. In the file table.js was created another function that put below ..:

function incluir_registro(id_usuario,dia_da_semana,inicio, fim)
{
dia_da_semana + ' inicio..: '+ inicio + '  fim..: '+ fim);  
 $.ajax
 ({
  type:'post',
  url:'m_h_02_i_horario.php',
  data:{inserir_registro:'inserir_registro',pid_usuario:id_usuario, pdia_da_semana: dia_da_semana , pinicio : inicio, pfim : fim },
  success:function(response) {
   if(response=="success")
   {
      window.alert('SUCESSO ' + id_usuario);   
   }
  }
 });
}

Then the logic is as follows:
The button in the html part calls the function add_row () with the parameters id_user and day_of_week. The function add_row (user_id, day_day) calls the insert function register (user_id, day_of_day, start, end). My difficulty was to do the include_register function, as I'm very weak in ajax script. I was not understanding how . Ajax worked. From what I could understand this function it works as follows: 01) - type: post -> - url: 'm_h_02_i_horario.php' -> is the php page that actually inserts the record) - date: {insert_register : 'insert_register', pid_user: user_id, pdia_day: day_day, pinicio: start, end: -> is the parameter where the parameters are passed to the url page (m_h_02_i_horario.php)
< - -> -> .php is executed correctly executes what is in this function

I hope these lines can be useful to the community.
Hugs.

    
04.08.2017 / 14:30