How to send a correct AJAX JSON?
<p>I have a form with only 2 inputs. I wanna send a JSON to my POST method. Although, all possibilities give back this error:</p>

<pre><code>415 (Unsupported Media Type)
</code></pre>

<p>I tried used this 3 ajax:</p>

<pre><code>        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()          
        })
</code></pre>

<p>Here is what I got after printing them on console:</p>

<pre><code>nome=yrt&amp;idade=09    //$("#idform").serialize()

{
"name": "yrt",       //all
"idade": "09"
}
</code></pre>

<p>And <code>$("#idform").serializeArray()</code> returned <code>[("name","yrt"),("idade","09")]</code></p>