admin管理员组文章数量:1397158
I got some trouble submitting a form with ajax.
Since HTML5 Form already have "required" validation within the input tag, there is no need for javascript validation check. However, because of that, I don't know how to use javascript(jQUERY) to submit a form AFTER those validation checks have been passed. In other words, how do I know whether the validations checks has passed or not?
e.g : ??condition?? (What condition should I put before loading the submitted page)? ("div").load(finishSubmittingForm.html) )};
Any idea?
Thanks
I got some trouble submitting a form with ajax.
Since HTML5 Form already have "required" validation within the input tag, there is no need for javascript validation check. However, because of that, I don't know how to use javascript(jQUERY) to submit a form AFTER those validation checks have been passed. In other words, how do I know whether the validations checks has passed or not?
e.g : ??condition?? (What condition should I put before loading the submitted page)? ("div").load(finishSubmittingForm.html) )};
Any idea?
Thanks
Share edited May 6, 2011 at 23:25 Victorgalaxy asked May 6, 2011 at 23:19 VictorgalaxyVictorgalaxy 3974 silver badges15 bronze badges2 Answers
Reset to default 3There are some API methods available. See developer.mozilla.
However, I would strongly advise you think carefully before relying on HTML5 validation. It definitely has some major drawbacks at this point in time, as it is still "in its infancy". I would say that for now, you would be better off using a JS validation library; jQuery Validation is excellent.
from specification:
If the user presses the submit button. The browser has to first validate the form and if the form is valid, the submit event is fired.
This means, that you can simply hook into the form's submit event and start your ajax.
$('form').bind('submit', function(){
//Ajax implementation here
});
But, Opera has a really nasty bug here. Opera first fires the submit event and then validates the form.
You can workaround this, by using the validation methods of HTML5. This would look like this:
$('form').bind('submit', function(){
if(!this.checkValidity || this.checkValidity()){
//Ajax implementation here
}
});
About the current state of the HTML5 form spec. There are some parts, that should extend the form spec. The features, which are currently implemented in FF4 and others (FF4 has less form features than Opera and Chrome, but very good implementation) are stable enough for production.
If you want to use HTML5 forms in all browsers, I would suggest the webshims HTML5 forms polyfill. It not only polyfills the incapable browsers, but also fixes some bugs in browsers, which haven't implemented the form feature according to the spec. For example, the Opera bug mentioned above will be automatically fixed.
本文标签: javascriptSubmit a HTML 5 Form with AJAXStack Overflow
版权声明:本文标题:javascript - Submit a HTML 5 Form with AJAX? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744651448a2617709.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论