内容简介:翻译自:https://stackoverflow.com/questions/9318372/jquery-load-to-post-all-elements-of-a-form-rather-than-having-to-specify-what
表单,我正在尝试更新以使用jQuery.load().如何将表单的所有元素作为POST参数传递,而不是必须指定要传递的参数?
表单元素是由脚本动态创建的,元素的数量以及元素的名称在很大程度上变化很大,以至于指定通过AJAX / POST传递哪些参数是不切实际的.是否有一种简单的方法可以传递给jQuery.load()<form></ form>中的所有元素标签好像传统上提交了表单一样?
您可以使用.serialize()来序列化表单的所有输入,以便与jQuery.load()调用一起提交.
$('form').serialize()
例如,使用jQuery.load()(只有GET,除非你传递一个数据对象,然后POST)
$.load( 'postTo.php', $('#yourFormId').serialize(), complete(responseText, textStatus, XMLHttpRequest){ //do your processing after the fact }))
使用,jQuery.ajax(),你可以使它POST
$.ajax({ 'url': 'postTo.php', 'type': 'POST', 'data': $('#yourFormId').serialize(), 'success': function(result){ //process here } });
翻译自:https://stackoverflow.com/questions/9318372/jquery-load-to-post-all-elements-of-a-form-rather-than-having-to-specify-what
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- php – 禁用表单元素的POST值
- 表单元素中readonly和disabled的区别
- 表单 – 避免Symfony强制显示表单字段
- 细说 Angular 2+ 的表单(二):响应式表单
- CSS 基础:块级元素、行内元素、替换元素、非替换元素
- 8款最新CSS3表单 环形表单很酷
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Understanding Computation
Tom Stuart / O'Reilly Media / 2013-6-3 / USD 39.99
Finally, you can learn computation theory and programming language design in an engaging, practical way. Understanding Computation explains theoretical computer science in a context you'll recognize, ......一起来看看 《Understanding Computation》 这本书的介绍吧!