I am having some trouble getting my rest resource working. I have created my own rest resource to save some data from a web-panel. I am trying to preform a ajax call tot the rest resource but it won’t work and I have no clue what I’m doing wrong.
I’ve tested my resource in the API Browser and it works there but I have no clue how to make the ajax call.
My rest resource:
@Path("/")
public class PasswordResource{
private final PasswordRepository passwordRepository;
private final Gson gson = new Gson();
@Inject
public PasswordResource(PasswordRepository noteRepository) {
this.passwordRepository = noteRepository;
}
@POST
@Path("/password/{issue}")
public void update(@PathParam("issue") String issueKey, String content) {
PasswordDto passwordDto = gson.fromJson(content, PasswordDto.class);
passwordRepository.saveUserContent(issueKey, passwordDto.getContent());
}
}
My web-panel javascript:
AJS.toInit(function($) {
AJS.$('#searchButton').click(function (){
AJS.$.ajax({
url:"jira/rest/passwordresource/1.0/password/" + document.getElementById("issueKeyInput").value,
type: "POST",
data:{"content": document.getElementById("passwordInput").value},
dataType: "json",
success: function(msg){
alert(msg);
}
});
});