Hi guys, I know this is a noob question, but I'm wondering what the best way to render a view from a request made not in the url bar of the browser, but from a js method.
I've got a button in one page that uses angular to make the following request when clicked:
$http({
method: 'GET',
url: 'game/gameView',
data: {
gameId: gameId
}
})
.then(
function success (res) {
console.log("Went to gameView");
console.log(res);
},
function error (res) {
console.log("Bad request")
}); //End of $http()
On the server I'm handling the request with a res.view()
My problem is that the while the the server is responding to the request with the html, the front end doesn't actually change, because I haven't told it WHAT to do with the html it just received from the server.
Is there a best practice for handling transitions like this? It feels wrong to just replace the whole page manually with something like:
$(html).html(res.data) //using jquery
But is there any other way? Should I use a different layout than the default, so I can receive less than a full page of html (no head, scripts, etc), and just replace the body in the above way? There is no way to have a request like the one I am making above with angular *directly* navigate me to the page served by res.view(), correct? What do you guys recommend?
Thanks for the help!