javascript - Send form email to a REST service using JSON -
how send form email rest service using json
i´m trying so:
// send mail $('#btn_send').click(function() { // data object contact this.name = $('#inputnome').val(); this.email = $('#inputemail').val(); this.subject = $('#inputassunto').val(); this.message = $('#textareamsg').val(); this.tojsonstring = function() { return json.stringify(this); }; $.ajax({ type: "post", url: "http://localhost:8080/mailws", data: contact.tojsonstring(), contenttype: "application/json; charset=utf-8", datatype: "json", success: function(data, status, jqxhr) { alert(status.tostring()); }, error: function(jqxhr, status) { alert(status.tostring()); } }); });
i think problem you're not binding onclick action button. try enclosing whole javascript in $( document ).ready(function() {});
or cleaner.
$( document ).ready(function() { $('#btn_send').click(function() { sendemail();// }); }); function sendemail(){ var valuesarr = new array(); valuesarr.push($('#inputnome').val()); valuesarr.push($('#inputemail').val()); valuesarr.push($('#inputassunto').val()); valuesarr.push($('#textareamsg').val()); var jsontext = json.stringify(valuesarr); $.ajax({ type: "post", url: "http://localhost:8080/mailws", data: jsontext, contenttype: "application/json; charset=utf-8", datatype: "json", success: function(data, status, jqxhr) { alert(status.tostring()); }, error: function(jqxhr, status) { alert(status.tostring()); } }); }
Comments
Post a Comment