I can not create a new client on the server

0

Good evening, I'm a student at JS, html. I'm trying to learn how I can do an inclusion on the server (I apologize if I describe with the incorrect word or term some step). I have to create a website to do a CRUD on the server. I have to implement JAVA SCRIPT Update, Create, Delete, Read. However, I have already done the READ and DELETE. I'm trying to do the CREATE. But I do not think I know any content. I've researched a lot and I can not include anything on the Server.

I'll send my code down:

<!DOCTYPE html>
<html><script 
src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><body><h2>TabelaDeClientes</h2><formid="formularioId">
Nome do cliente:<input type="text" id="form">
uf: <input type="text" id="form" >
Renda Mensal: <input type="text" id="form" >
<button type="submit" id="criarId">Criar</button>
</form>
<br><br> <button type="button" id=tabela>Tabela</button>  
<br><br>
Resultado:<br>
<p id="listaCliente" ></p>
<script>
var url="httpEndereço";
$(document).ready(function(){
$("#tabela").click(function(){
$.get("https://clienteweb2017.000webhostapp.com/crud_ajax_json/
getDadosClientes.php")
    .done(function(data,status){
        var obj = JSON.parse(data);
        console.log(obj);
        montarTabela(obj);
        })

    .fail(function(){
    alert("Problema de conexão");
    });


    });
 function montarTabela(obj){
  var i;

  //console.log (response.responseXML);

  //var xmlDoc = response.responseXML;  

  var table="<table border=1  style=border-collapse:'collapse';><tr> 
  <th>Id</th><th>Nome</th><th>uf</th><th>Renda Mensal</th><th>remover</th> 
  </tr>";

  //var x = xmlDoc.getElementsByTagName("ALBUM");

   for (n of obj.data) { 
   table += "<tr><td>" + n.id +"</td><td>" +n.nome +
   "</td><td>" + n.uf +"</td><td>" + n.rendamensal+"</td><td><a 
    href='#'class='excluir'>remover</a></td></tr>";
   }
   $("#listaCliente").html(table);
   }
    $("body").on("click", ".excluir",function(){

    var Cid=$(this).parent().siblings(0).html();


   $.get("https://clienteweb2017.000webhostapp.com/crud_ajax_json/
   deleteCliente.php?id="+Cid)
    .done(function(){
        //alert("Removido!!!");
        })

    .fail(function(){
    alert("Problema de conexão");
    });
    });
    });//Fim da Ready
    var xhttp=new XMLHttpRequest();
    $(document).ready(function(){

     $("body").on("click", "#criarId",function(){

    var criacao=$('#formularioId');
    $.get("https://clienteweb2017.000webhostapp.com/crud_ajax_json/
    createCliente.php?nome="+criacao)
      .done(function(){
         //alert("Removido!!!");
            })

      .fail(function(){
       alert("Problema de conexão");
       });
        xhttp.send();
       });
        });//Fim da Ready
   </script>
   </body>
    
asked by anonymous 18.11.2018 / 01:05

1 answer

1

How is the structure of the users table? And it helped tb see createCliente.php. When working through AJAX, you should always be aware of the Network tab of the browser console, in any case, you are apparently sending the form and not just the value of the input 'name'. Moreover, all form fields have the same id and should not.

<form id="formularioId">
Nome do cliente:<input type="text" **id="form"**>
uf: <input type="text" **id="form"** >
Renda Mensal: <input type="text" **id="form"** >
<button type="submit" id="criarId">Criar</button>
</form>

It should be, for example:

<form id="formularioId">
Nome do cliente:<input type="text" id="nomeCliente">
uf: <input type="text" id="ufCliente" >
Renda Mensal: <input type="text" id="rendaCliente" >
<button type="submit" id="criarId">Criar</button>
</form>

So, via javascript:

var criacao=$('#nomeCliente').val();
    $.get("https://clienteweb2017.000webhostapp.com/crud_ajax_json/
    createCliente.php?nome="+criacao)
      .done(function(){
         //alert("Removido!!!");
            })

      .fail(function(){
       alert("Problema de conexão");
       });
        xhttp.send();
});

Finally, do you have to use GET to place orders? POST would be much better - reasonably more secure.

    
18.11.2018 / 12:52