'JS Function won't generate necessary buttons
I am currently making a budget version of UNO using Java and JavaScript and I am running all of it on a GlassFish Server.
I made a function to generate the starting hand of 7 cards for each player, yet it doesn't behave like I want it to. (I am kind of an amateur in programming)
Here is my function for generating the cards:
function getStartingCards(){
fetch('./api/cards')
.then(response => response.json() )
.then( data => {
_cards = data;
let html = "";
data.forEach(d => html += `<tr><td><button class="card1">test</button></td></tr>`);
document.getElementById("table1").innerHTML = html;
console.log("test");
})
}
That was my front-end, which is supposed to generate the cards itself with some things it receives from the back-end:
@Path("/cards")
public class CardsResource {
@Context
ContainerRequestContext c;
@GET
public List<Hand> getCard(){
return HandDatabase.getInstance().getCardList();
}
@POST
public Response addCard(@QueryParam("id") int id){
try{
Card card = Deck.getInstance().dealCard();
String hand = (String)c.getProperty("user");
HandDatabase.getInstance().getHandById(hand).addCard(card);
return Response.ok(Deck.getInstance().dealCard()).build();
}catch (Exception e){
return Response.status(Response.Status.NOT_FOUND).build();
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|