I'm currently working on a comment section for a Web Client.
There are two tables involved - one for the comments and another for the users. My goal is to send input data from HTML <input>
tags to a Java Service where the data will be processed. However, I've encountered an HTTP-415 error and I'm stuck on how to resolve it.
The approach I am using involves AJAX in JavaScript to transmit the data.
HTML
ID: <input type="text" name="id" value="1" readonly/> <br/>
Author: <input type="text" name="author"/> <br/>
comment: <input type="text" name="comment"/> <br/>
<button id="submit" type="Button" >Submit</button>
Javascript
function addPost(givenID){
var $author = $("#author");
var $comment= $("#comment");
var $id = $("#id")
$("#submit").on("click", function(){
var post = $author.val()+"*"+ $id.val()+"*"+ $comment.val();
$.ajax({
type: "POST",
url: "api/kommentar",
data: post,
success: function(){
console.log("SUCCESS");
},
error: function(){
console.log("FAILURE");
}
});
});}
Java
@Path("/kommentar")
public class KommentarService {
@EJB
private KommentarManagement postMgmt;
public KommentarService() { }
@POST
@Consumes("text/plain")
public void addPostsAsJson(String income) {
System.out.println(income);
//CODE TO HANDLE...
}