(vĆa https://www.youtube.com/watch?v=ozC4XvLQECk)
A YouTube video course about Jade.js
seen from United States
seen from Germany
seen from Russia
seen from China
seen from Japan

seen from United States
seen from United States
seen from Türkiye
seen from United Kingdom
seen from Saudi Arabia

seen from United States
seen from Saudi Arabia
seen from Yemen
seen from United States
seen from United States
seen from United States

seen from United Kingdom

seen from Singapore
seen from United Kingdom
seen from Saudi Arabia
(vĆa https://www.youtube.com/watch?v=ozC4XvLQECk)
A YouTube video course about Jade.js

Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
Free to watch ⢠No registration required ⢠HD streaming
Render a jade template as a result of an AJAX call in Express
Today, while doing a fun side-project, I ran into a problem I couldnāt find an answer to online. I was sure itās trivial but ended up searching for 3 hours until I figured it out.
Letās say your index page is rendered using a jade template by Express. A button on your page makes an AJAX call to your website. You want the result to update only a part of your page and not to reload it. You also want that call to be rendered using a jade template and not parse it yourself.
app.js:
app.get('/', function (request, response) { Ā Ā response.render('index'); });
index.jade:
extends layout block content Ā Ā input#input(type='search' autofocus) Ā Ā a#button Search Ā Ā section#results
If you make a request now toĀ ā/ā you will see just a search box and a link. So we need to add some functionality for when clicking the link.
javascript.js
var button = document.getElementById('button'); var input = document.getElementById('input'); button.addEventListener('click', function(e) { Ā Ā e.preventDefault(); Ā Ā var url = '/search/?q=' + input.value; Ā Ā var xmlhttp = new XMLHttpRequest(); Ā Ā xmlhttp.open("GET", url, true); Ā Ā xmlhttp.send(); Ā Ā xmlhttp.onreadystatechange = function() { Ā Ā Ā Ā if (xmlhttp.readyState==4 && xmlhttp.status==200) Ā Ā Ā Ā { Ā Ā Ā Ā Ā Ā console.log('Server said: ', xmlhttp.responseText); Ā Ā Ā Ā Ā Ā document.getElementById('results').innerHTML = xmlhttp.responseText; Ā Ā Ā Ā } Ā Ā }; });
When the button is clicked - an AJAX GET call is made toĀ ā/searchā on the server. Query parameterĀ āqā contains the value of the search box. Once the server replies, the reply will be added as an HTML in section#results. Letās handle the call on the server.
app.js:
app.get('/search', function(request, response) { Ā Ā // The query parameter is available in: request.query.q Ā Ā var dummy_data = [{title: 'Intersterller', year: 2014}, {title: 'Inception', year: 2010}]; Ā Ā response.render('movies', {results: dummy_data}); }
Youād probably want to take the search query entered on the page (available as request.query.q) and get some real data from somewhere. For this example we will just use an array containing 2 movie objects. The server then uses movies.jade to render the data and return it to the client.
movies.jade
for result in results Ā Ā p.movie #{result.title} (#{result.year}) Ā Ā Ā Ā Ā Ā
Thatās it. The server will take the data and use it to render movies.jade. It will then send it back to the client. The response will look something like:
<p class=āmovieā>Intersterller (2014)</p><p class=āmovieā>Inception (2010)</p>Ā Ā Ā Ā Ā Ā
The client will take this HTML and insert it to the section#results part of the page.
I hope this helps.
JadeJS Syntax
Indentation is VERY important.Ā
No tabs allowed if you use spaces.
Ā script(type='text/javascript', src='/js/mobile.js')
Ā link(href='/stylesheets/style.css', rel='stylesheet')Ā
Ā meta(name="viewport", content="width=device-width, initial-scale=1.0")
Ā div(data-role="page")