Thursday 8 June 2017

Why is my page reloading even though I have event.preventDefault (form handling jquery + node.js)

I am using jquery to asynchronously post my data to my db using node.js and express.js

Here is roughly what I am doing: index.html: <form id='#mailer' action='/mail/new' method='post'> <input name='mycontent'/> <input type='submit'/> </form>

script.js: $(#mailer).submit(function(e){ e.preventDefault(); $.post('/mailer/new',{mycontent:mycontent}); });

app.js: app.post("/mailer/new,function(){ //insert into database }

So it is essentially submitting to my database but ignoring the e.preventDefault because my page shows the loader wheel when I press submit



via mohammad chughtai

No comments:

Post a Comment