jQuery Validate SubmitHandler with Ajax Submission Not being hit

感情迁移 提交于 2019-11-29 18:18:30

I got it working and updated my question as to how.. but could you explain why this syntax works over the others?

Your .submit() handler is a bad idea because it's going to interfere with the way the jQuery Validate plugin handles the form's submit event. (Basically, you've prevented the default submit and then never turned it back over to the Validate plugin.) ASP or not, this is absolutely not the way to do it. The Validate plugin provides the submitHandler function for any purpose where you need to capture this event.

Your .settings.submitHandler works because it's the only way to define the submitHandler function when you have no access to write your own .validate() method (thanks to Unobtrusive Validation plugin). As per the documentation, the submitHandler is the "right place to submit a form via Ajax after it is validated".


so if I were not to use the unobtrusive, then I could use my original code?

The jQuery Validate plugin is initialized via the .validate() method, normally on page load. This method can only be called one time and all subsequent calls will be ignored. When you use ASP and the Unobtrusive Validation plugin, it constructs and calls the .validate() method for you, therefore you can no longer set any options or rules by calling .validate() yourself.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!