edit: i have already read this question "How to use Servlets and Ajax?" it talks about generating something in the same page, i want to take data from the page to the servlet then redirect to another page and fill some existing text areas.
Hi i'm new on stackoverflow and i am new in programming. I'm doing a web app where i have to search something from an html page to the db, and this is not a problem.
The problem is that when the ajax call produces the data i have to create a button too that redirects me to an existing html page, at the same time the button have to send the data to load in the other page to the servlet (i have already done this, it now produces the json but i don't know how to insert it into the other page) and i don't know how to say to the servlet "hey take this little data from the search page, find the record and load the edit page with the data i want in!".
I prefer to not use a JSP but if it is the only way..
these are the buttons in the search function:
<form>
<button name="delA" class="btn btn-danger" type="submit" value="' + data[i].key + '" formaction="delete" formmethod="post" onclick="clickedConfirm(event)"></button>
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
<button name="row" class="btn btn-warning" type="submit" value="' + data[i].key + '" href="http://localhost:8080/label-editor/edit.html" formaction="edit" formmethod="get"></button>
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</form>
this is the edit servlet:
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
LabelManager lm = new LabelManager();
JSONSerializer js = new JSONSerializer();
String json = "";
String paramRow = req.getParameter("row");
ServletOutputStream out = resp.getOutputStream();
if(paramRow != null){
Collection<LabelModel> label = null;
label = lm.searchLabelK(paramRow);
json = js
.exclude("*.class")
.exclude("locale.ISO3Language")
.exclude("locale.baseLocale")
.exclude("locale.country")
.exclude("locale.displayCountry")
.exclude("locale.displayLanguage")
.exclude("locale.displayScript")
.exclude("locale.displayVariant")
.exclude("locale.language")
.exclude("locale.localeExtensions")
.exclude("locale.script")
.exclude("locale.variant")
.serialize(label);
resp.setContentType("application/json");
out.print(json);
out.flush();
}
}
I was thinking about an ajax call like this but i don't know how to complete it, i cant find anything that could help:
function editlabel() {
$.ajax({
url : 'edit',
data : {
row : getUrlParameter('row')
},
success : function(data, status, xhr) {
$('#edit').submit(function(response) {
if (data.length > 0) {
$('#key').val(data[0].key)
console.log("stampo il titolo");
for (var i = 1; i < data.key.length; i++) {
var row = data[i];
$('#val' + i).val(row.value)
console.log("ciclo " + row);
}
}
});
},
error : function(req, status, err) {
console.log('Something went wrong', status, err);
}
});
}
Thank you for your time and your help p.s. sorry for my bad english