1
I’m trying to use AJAX
$.ajax({
url : urlN, // <<- "/log"
type: "post",
success : function(json) {
console.log(json);
document.getElementById('content').innerHTML = json;
}
setInterval(refreshDiv, 5000);
to update, at each 'X' time, only a part of an HTML page (<div>
). The problem is, I couldn’t get the contents of my file because my controller returned the name of my view, which resulted in this:
After several attempts, I discovered that I could not pass the view name through my controller, but an object from the file I would like to access. Under advice, I added the @Responsebody notation so that the return of the method is automatically written in the customer response. The problem is that this way, I "lose" my view and the only return displayed is the content itself. That is, my problem has been reversed..
My controller:
@RequestMapping(value = "/log", method = RequestMethod.POST)
@ResponseBody
//String - View
public Log jsonLogContent(@Valid Log log, BindingResult bindingResult, Map<String, Object> model) {
if (log.getInitLine() == 0 && log.getFinalLine() == 0) {
try {
fileNumberLines(log);
log.setPathFile(logsDir + "/" + log.getFilename());
log.setContent(getLogContentByRange(0, log.getInitLine(), log.getFinalLine(), log.getPathFile()));
} catch (IOException e) {
logger.error(e.getMessage());
}
} else {
log.setContent(getLogContentByRange(0, log.getInitLine(), log.getFinalLine(), logsDir + "/" + log.getFilename()));
}
model.put("path", logsDir);
model.put("log", log);
model.put("currentPage", "logs");
model.put("root", root);
//return "log"; - View
return log; // Obj
}
My doubt:
Is there any way around this situation? Making it possible two URL’s for the same controller? Or a way for the view to load first and then the object?