Hello, Someone to help me, since a day I can not post the variable following a post that is recover by a javascript script, jquery. I can not even retrieve the message and object parameters but the other two, which are hidden fields, load on the js file before posting them to a spring controller.
the problem is that the two object and message parameters are not retrieved by the js script.
Here is my form :
and my js script is here :<form method="POST" class="form-inline" id="sendMailUser" modelAttribute="xxxxxx" > <!--Object--> <div class="form-group" > <label for="messageObject" class="col-sm-25 control-label TitreAcceul">Objet :</label> <div class=" " id="messageObject"> <div class="col-xs-12 col-sm-8 col-md-4"> <input type="text" id="messageObject" name="messageObject" class="form-control" placeholder=" " autofocus="true" size="60" /> </div> </div> <!--Espace entre les input --> <div class="EspaceChampFormFrim" > </div> <!--Espace entre les input --> <!--Prenom--> <label class="col-sm-25 control-label TitreAcceul">Message :</label> <div class=" " id="messageContenue"> <div class="col-xs-12 col-sm-12 col-md-8"> <textarea id="messageContenue" class="form-control" name="messageContenue" placeholder="Veiller Ajouter Votre Message ..." /> </textarea> </div> </div> <!--Espace entre les input --> <div class="EspaceChampFormFrimMail" > </div> <!--Espace entre les input --> <!--Email Destinataire --> <input type="hidden" id="messageDestinataire" value="${xxxx}" /> <input type="hidden" id="messageDestinataireIdUser" value="${xxxxx}" /> </div> <!--Button --> <p align="center" > <button type="submit" class="btn btn-primary has-spinner" ><span class="glyphicon glyphicon-send"></span> Envoyez</button> <a href="<%=urlapplication%>xxxx" class="btn btn-primary has-spinner"><span class="glyphicon glyphicon-eject"></span> Annuler</a> </p> </form>
$(document).ready(function () { $('#sendMailUser').submit(function (e) { // Prevent the form from submitting via the browser. e.preventDefault(); var obj = $("messageObject").val(); var dataMessage = { messageObject: $("#messageObject").val(), messageContenue: $("#messageContenue").val(), messageDestinataire: $("#messageDestinataire").val(), messageDestinataireIdUser: $("#messageDestinataireIdUser").val() }; //Log dataMessage before post console.log("dataMessage before post: " + dataMessage); //------------------------ bootbox.dialog({ title: "<i class='glyphicon glyphicon-send'></i> FRIM : ENVOIE MAIL COLLABORATEUR !", message: "<p class = 'TitreAcceuil'><i class='glyphicon glyphicon-send'></i> Etes Vous Sur D'envoyer Votre Mail à " + dataMessage["messageDestinataire"] + " ?</p>", buttons: { success: { label: "<span class='glyphicon glyphicon-eject '></span> Annuler", className: "btn-danger", callback: function () { $('.bootbox').modal('hide'); } }, danger: { label: "<span class='glyphicon glyphicon-send'></span> Envoyer!", className: "btn-success", callback: function () { $.ajax({ type: "POST", url: "/xxxx/yyyyyyyyyyy", data: dataMessage }) .done(function (data) { bootbox.alert('<p class = "alert alert-success"> <span class = "glyphicon glyphicon-send"></span> Message Envoye Avec Succces....</p>' , function (result) { window.location = ("/MooUpdateSpringAppFrim/FrimSendMailStaf"); }); console.log("SUCCESS: ", data); }) .fail(function (data) { bootbox.alert('<p class = "alert alert-warning"> <span class = "glyphicon glyphicon-send"></span> Erreur Envoie Mail....</p>'); console.log("SUCCESS: ", data); }) } } } }); }); });
thanks