I try to make a request ajax but it does not send any dice

Asked

Viewed 27 times

-1

$(document).ready(function() {
  var lerId = localStorage.getItem("id");
  var dados = localStorage.getItem(lerId);
  var dadoss = dados.split(",");

  var titulo = dadoss[1];
  var imagem = dadoss[2];
  var descricao = dadoss[3];
  var email_necessitado = dadoss[4];
  var tipo_trab = dadoss[5];
  var email_nece = parseInt(email_necessitado, 16)
  $("#header_necessidade").css({
    "background-image": "url('" + imagem + "')",
    "box-shadow": "0 4px 8px 0 rgba(0,0,0,0.2)"
  })
  $("#titulo_necessidade").html(titulo);
  $("#img_necessidade").attr("src", imagem);
  $("#descricao_necessidade").html(descricao);
  $("#email_necessitado").html(tipo_trab);
  $("#email_prop").attr("value", localStorage.getItem("Email"));
});
$("#btn_env").click(function() {
  console.log("ahahahhah");
  $.ajax({
    url: "https://jobsssssss.000webhostapp.com/insert_prop.php",
    type: "POST",
    dataType: "json",
    data: {
      descricao: $("#text_descricao").val(),
      valor: $("#input_valor").val(),
      email_trabalhador: $("#email_prop").val(),
      id_necessidade: localStorage.getItem("id"),
      email_necessitado: email_necessitado,
      img_trab: localStorage.getItem("Foto")
    },
    success: function(s) {
      console.log(s);
    },
    error: function(e) {
      console.log(e);
    },
  });

});
<!DOCTYPE html>
<html lang="pt-br" dir="ltr">

<head>
  <meta charset="utf-8">
  <title></title>
  <link rel="stylesheet" href="../css/index.css">
  <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/sweetalert2@8"></script>
  <link href="https://fonts.googleapis.com/css?family=Montserrat|Open+Sans|Russo+One|Ubuntu|ZCOOL+QingKe+HuangYou" rel="stylesheet">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.1/jquery.modal.min.js"></script>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.1/jquery.modal.min.css" />
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.12/jquery.mask.min.js"></script>
  <script type="text/javascript" src="../js/necessidade.js"></script>

</head>

<body>
  <header id="header_necessidade">
    <a href="index.html" class="tab_item" id="back"><i class="material-icons" style="font-size:25px;">exit_to_app</i></a>
    <center>

      <h1 id="titulo_necessidade"></h1>

    </center>
  </header>
  <center>
    <div class="modal" id="modal_prop">
      <h2 class="title_modal">Nova Proposta</h2>
      <br>
      <p>Email</p>
      <input type="text" name="" value="nome" readonly id="email_prop">
      <br>
      <p>Valor</p>
      <input type="text" name="" value="R$" id="input_valor">
      <br>
      <p>Descricao</p>
      <textarea name="name" rows="8" cols="80" placeholder="Por Favor NÃO deixar telefone ou email para contato" id="text_descricao"></textarea>
      <br>
      <button type="button" name="button" id="btn_env">Enviar Proposta</button>
    </div>
    <section id="section_necessidade">
      <div class="img_necessidade">
        <img src="" alt="" id="img_necessidade" width="40%">
      </div>
      <div class="descricao_necessidade">
        <textarea name="name" cols="5" id="descricao_necessidade" readonly></textarea>
      </div>
      <div class="email_necessitado">
        <textarea name="name" rows="2" cols="80" id="email_necessitado" readonly></textarea>
      </div>
      <br>

    </section>
    <button id="btn_prop">
        <a href="#modal_prop" rel="modal:open" id="prop" > Nova Proposta</a>
      </button>
  </center>


</body>
<script type="text/javascript">
  $("#input_valor").mask("#.##0,00", {
    reverse: true
  })
</script>


</html>

1 answer

0

Dear your question this energy too.

Try to develop in a modular way, testing each part separately.

  • puts a console.log( $("#text_description"). val() ) before the ajax request to be sure the correct value.
  • passes only one value per parameter before sending all parameters to test.

You gotta help the guys help you.

  • So brother when I run it appears in the console only an array with the data I send but n inserts nothing in the database

Browser other questions tagged

You are not signed in. Login or sign up in order to post.