I am trying to POST data to a REST api without using AJAX. I want to send the data in JSON format. I have the following code but am stuck trying to figure out how to conve
You can add a hidden input field with the json value, like this -
function submitform() {
var url = '/users/' + $('#user_id').val();
$('#myform').attr('action', url);
var data = JSON.stringify({
"userdata": $('#user_data').val()
})
$('<input type="hidden" name="json"/>').val(data).appendTo('#myform');
$("#myform").submit();
}
You can access your json using json
parameter (name of hidden input)