Sending form with ajax json

0

Hello, my question is about submitting a form via ajax. I would like to get these form elements and send via ajax. I need to save and send the form data, the "grid", and the json question and answer. I thought of writing those elements in a variable.

My role:

sendQuestion : function() {

    // pega valor estrelas
    var starsValues = $( ".nota" ).val();

    //pega valor comentario
    var message = $('textarea#comment').val();

    $('.btnAvaliacao').click (function() {

       var formEvaluation = $("#sendEvaluation");
       alert ('click ok');
       $.ajax({

          url:'https://xxx.local:9002/vendedor/evaluate',
          type: "post",
          async: false,
          dataType: "json",
          data: formEvaluation.serialize(),
          success: function(formEvaluation) {
             alert ('ok');
             console.log (formEvaluation);
          },
          error: function() {
             alert ('ok erro');
          },
       });

    });
}

My form html:

<form id="sendEvaluation">
     <div class="form-group row">

          <div class="col-sm-10 rating-seller">
               <span class="titleModalSeller">Avalia&ccedil;&atilde;o do Seller</span>
               <div class="rating rating-set js- ratingCalcSet" data-rating="{"}">
                    <div class="rating-stars">
                         <span class="nota"></span>
                    </div>
               </div>
          </div>
      </div>

      <fieldset class="form-group">
          <div class="row">

               <div class="col-sm-6" id="results"></div>
               <div class="col-sm-6" id="results-answer"></div>

          </div>
      </fieldset>

      <div class="form-group row">
          <div class="col-sm-12">
               <span class="titleModalSeller">Coment&aacute;rio</span>
               <textarea class="form-control" rows="5" id="comment"></textarea>
          </div>
      </div>

      <div class="form-group row">
          <div class="col-sm-10">
               <button type="submit" class="btn btnAvaliacao">Enviar Avalia&Ccedil;&Atilde;o</button>
          </div>
      </div>
</form>

My json, I need to get the items:

{
"orderId" : "0000001-A",
"grade" : 5,
"comment" : "My comment",   
"answers" : [
    {
        "questionCode" : "1",
        "answerValue" : "true" 
    },
    {
        "questionCode" : "2",
        "answerValue" : "false" 
    },
    {
        "questionCode" : "3",
        "answerValue" : "false" 
    },
    {
        "questionCode" : "4",
        "answerValue" : "true" 
    },
    {
        "questionCode" : "5",
        "answerValue" : "4" 
    },
    {
        "questionCode" : "6",
        "answerValue" : "2" 
    }
]
}
    
asked by anonymous 04.09.2018 / 19:36

0 answers