dzikulisz cezar
dzikulisz cezar

Reputation: 11

JavaScript function to open modal dialog in Spring application

I'm completely new to JavaScript. Can someone please explain what each line in this function does?

function openPoolModal(id){

console.log("I've been called");

$.ajax({
    url: "/" + id,
success: function(data){
    $("#PoolModalHolder").html(data);
    $("#PoolModal").modal("show");
}
});
}

I work with Spring & Thymeleaf and what I understand so far is that controller method is called via url. Controller method generates data and then what?

Here's the controller method:

@RequestMapping("/{id}")
public String getNetworkInfo(Model model, @PathVariable String id){

    model.addAttribute("poolHashrate", netService.getPoolHashrate(new Long(id)));

    return "networkDetails :: modalContents";
}

It also returns a part of .html fragment through Thymeleaf th:fragment attribute. I'm using https://qtzar.com/2017/03/24/ajax-and-thymeleaf-for-modal-dialogs/ tutorial, but I don't get the PoolModalHolder part.

Upvotes: 0

Views: 882

Answers (1)

to understand that code, you need to look for the th:fragment modalContents, it should be in the file networkDetails.

model.addAttribute("poolHashrate", netService.getPoolHashrate(new Long(id)));

return "networkDetails :: modalContents";

The controller gets the "poolHashrate" object, then it's parsed through Thymeleaf on the fragment modalContents and an html code is generated.

The ajax code, receives that Html code and sets it as content of PoolModalHolder.

Upvotes: 1

Related Questions