Sending form with ajax json

Asked

Viewed 162 times

0

Hello, my question is about sending a form via ajax. I would like to take these form elements and send via ajax. I need to save and send the form data, the "grid", and the question and answer of this json. I thought to save in a variable that elements.

my job:

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 html form:

<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" 
    }
]
}
  • it was not clear what you need or what the problem is

  • opa, I need to save send the form data, this "grid", and the question and answer like this one from this json Answers" : [ { "questionCode" : "1", "answerValue" : "true" },

  • JSON.stringify(obj);

No answers

Browser other questions tagged

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