I have a form with only 2 inputs. I wanna send a JSON to my POST method. Although, all possibilities give back this error:
415 (Unsupported Media Type)
I tried used this 3 ajax:
console.log($("#idform").serializeArray());
console.log($("#idform").serialize());
var nome = "\"" + $("#idnome").val() + "\"";
var idade = "\"" + $("#ididade").val() + "\"";
var all = "{\n"+"\"name\": "+nome+",\n"+
"\"idade\": "+idade+"\n"+"}";
console.log(all.toString());
$.ajax({
url : 'http://localhost:8080/DBRest/rest/escreve',
type : "POST", // type of action POST || GET
dataType : 'json', // data type
data : all
})
$.ajax({
url : 'http://localhost:8080/DBRest/rest/escreve',
type : "POST", // type of action POST || GET
dataType : 'json', // data type
data : $("#idform").serializeArray()
})
$.ajax({
url : 'http://localhost:8080/DBRest/rest/escreve',
type : "POST", // type of action POST || GET
dataType : 'json', // data type
data : $("#idform").serialize()
})
Here is what I got after printing them on console:
nome=yrt&idade=09 //$("#idform").serialize()
{
"name": "yrt", //all
"idade": "09"
}
And $("#idform").serializeArray()
returned [("name","yrt"),("idade","09")]