I have an input submit, after attaching an onclick handler on it, what's the standard way to prevent a post request to "form action=xxx" url? Is it "return false", or "e.preventDefault", or "e.stopPropogation"?
            Asked
            
        
        
            Active
            
        
            Viewed 44 times
        
    0
            
            
        - 
                    `e.preventDefault()`. – Mohammad Oct 12 '16 at 03:33
- 
                    Either `return false` or `preventDefault` should be sufficient. – Alexander Nied Oct 12 '16 at 03:35
- 
                    See [event.preventDefault() vs. return false](http://stackoverflow.com/questions/1357118/event-preventdefault-vs-return-false) and [What's the difference between event.stopPropagation and event.preventDefault?](http://stackoverflow.com/questions/5963669/whats-the-difference-between-event-stoppropagation-and-event-preventdefault) – Tushar Oct 12 '16 at 03:35
1 Answers
0
            just call preventDefault() like this
$("#myform").submit(function(event){
  event.preventDefault();  
  // DO SOMETHING
});
 
    
    
        Alongkorn
        
- 3,968
- 1
- 24
- 41
- 
                    
- 
                    it is up to you, but put it in the beginning may be better if your code if too long or may contain promise or callback – Alongkorn Oct 12 '16 at 03:56