Oi, não está aparacendo o Alert ao enviar enviar a promoção do formulario. A index está carregando mas, apresenta os seguites erros no console) Obrigado.
GET http://localhost:3000/socket.io/socket.io.js 404 (Not Found)
(index):1 Refused to execute script from 'http://localhost:3000/socket.io/socket.io.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
(index):316 Uncaught ReferenceError: io is not defined
at (index):316
(anonymous) @ (index):316
2(index):1 GET http://localhost:3000/css/site/museo-500.woff 404 (Not Found)
(index):303 GET http://cdn.shopify.com/s/files/1/0155/7645/t/177/assets/logopagseguro.png?11981592617154272979 404 (Not Found)
2(index):1 GET http://cdn.shopify.com/s/files/1/0155/7645/t/177/assets/sprites.png?17557711475382243135 404 (Not Found)
(index):300 GET http://cdn.shopify.com/s/files/1/0155/7645/t/177/assets/accepts_paypal.png?11981592617154272979 404 (Not Found)
app
var app = require('./config/express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.set('io',io);
app.listen(3000,function(){
console.log("servidor rodando");
});
index
<!-- social-footer -->
<p class="footer-title">Receba as Novidades e Lançamentos</p>
<div id="form-newsletter">
<form
action=""
method="POST" id="ss-form" class="form-newsletter">
<ul>
<li><input type="hidden" name="pageNumber" value="0"/><input
type="hidden" name="backupCache" value=""/><input
type="email" name="entry.0.single" value="" class="ss-q-short"
id="entry_0" placeholder="seu@email.com"/></li>
<li><input type="submit" name="submit"
value="Quero Receber!" id="submit-newsletter"/></li>
</ul>
</form>
<ul>
<li class="ie8"><a
href=""
rel="nofollow">Receba as Novidades e Lançamentos</a></li>
</ul>
</div>
<ul class="footer-payments">
<li><img class="accepts-paypal"
src="//cdn.shopify.com/s/files/1/0155/7645/t/177/assets/accepts_paypal.png?11981592617154272979"
border="0" alt="Paypal" width="130" height="80"/></li>
<li><img class="accepts-pagseguro"
src="//cdn.shopify.com/s/files/1/0155/7645/t/177/assets/logopagseguro.png?11981592617154272979"
border="0" alt="PagSeguro" width="180" height="26"/></li>
</ul>
</div>
</div>
</footer>
<!-- <script>
setInterval(function(){
//ajax pedindo por novas promocoes
}, 10000);
</script> -->
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io();
socket.on('novaPromocao',function(data){
alert("Livro em promocao " + data.livro.id)
});
</script>
</body>
</html>
promocoes
module.exports = function(app) {
app.get("/promocoes/form",function(req,res){
var connection = app.infra.connectionFactory();
var produtosDAO = new app.infra.ProdutosDAO(connection);
produtosDAO.lista(function(erros,resultados){
res.render('promocoes/form', {lista:resultados} );
});
connection.end();
});
app.post("/promocoes",function(req,res){
var promocao = req.body;
console.log(promocao);
app.get('io').emit('novaPromocao',promocao);
res.redirect('promocoes/form');
});
}
form
<html>
<body>
<form action='/promocoes' method="post">
<div>
<input type="text" name="mensagem"/>
</div>
<div>
<select name="livro[id]">
<% for(var i=0;i<lista.length;i++) {%>
<option value='<%=lista[i].id%>' > <%=lista[i].titulo%> </option>
<%}%>
</select>
</div>
<input type="submit" value="Cadastrar promoção"/>
</body>
</html>