I am trying using ajax for the first time. I have a working site and want to make it improve, therefore I dont want to redirect the clients on each post, I want to use AJAX and do a databse call in the backend with node.js.
For HTML I am using EJS. I want to let AJAX get called when the page is loaded. All that is already working.
My problem is, that I am using an if call in EJS.
its like:
if(variableX === 0){
render this header
} else{
render login header with name
}
The function in the backend gets called, but its not going to render the variables in my EJS file.
Can anyone help?
EJS:
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
type: 'post',
url: '/',
dataType: 'text',
async: false
})
});
</script> <script type="text/javascript">
$(document).ready(function() {
$.ajax({
type: 'post',
url: '/',
dataType: 'text',
async: false
})
});
</script>
pages.js:
res.render('home', {
pageName: "",
userName: result[0].twitchName,
isLive: liveStatus,
userID: result[0].id,
benachrichtigung: benachrichtigung,
twitchPBUrl: twitchPBLink
});
}
Thank you so much in advance :)
The best regards, Joshy
The point of Ajax is that:
It does not:
You can:
<form> instead of using Ajax. The response to a form submission is rendered in the viewport (in the same way that following a link or typing a URL in the address bar is).