</div>
</div>
<div class="grid--cell mb0 mt4">
<a href="/questions/22443146/jquery-ajax-and-java-server-lost-data" dir="ltr">jquery ajax and java server, lost data</a>
<span class="question-originals-answer-count">
(1 answer)
</span>
</div>
<div class="grid--cell mb0 mt8">Closed <span title="2014-03-17 09:20:22Z" class="relativetime">6 years ago</span>.</div>
</div>
</aside>
$.ajax(
{
type: "POST",
data: "koala",
url: "http://localhost:555",
cache: false,
success: function(result)
{
},
failure: function()
{
}
});
what will the syntax be to get the value i just sent though with ajax in my java? how will i get the value "koala". assuming you have accpeted the clientSocket connection
</div>
data accepts a dictionary. i think you have to write something like
data: {"koala": "koala"},
then your server can get and manipulate the data with the variable name "koala". what the server send back is stored in parameter result.
Using JAX-RS and Jersey your backend would be something like this
@Path("/")
public class MyResource {
@POST
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Animal createAnimal(final String animalName) {
return dao.create(animalName);
}
}
Sring MVC is quite similar as well.