Lithicas Lithicas - 1 month ago 8
Javascript Question

Convert input element to JSON and send to REST service

I'm trying to convert a HTML input element and the text within to a JSON object and then send it to a REST service.

How do I go about doing this using vanilla JS, not JQuery or any other libs. I have no clue what to put inside http.send() to send the text inside the input field.


<input id="answer" name="message" type="text" onclick="sendAnswer()" />


function sendAnswer() {"POST", nextUrl, true);
http.setRequestHeader("Content-type", "application/json");



If you're sending a post request, you put the JSON data for your request body inside the https.send()

something like:

var data = JSON.stringify({"email":"","name":"Bob"});