ajax -jquery.load()用于POST表单的所有元素,而不必指定POST的内容

栏目: jQuery · 发布时间: 6年前

内容简介:翻译自:https://stackoverflow.com/questions/9318372/jquery-load-to-post-all-elements-of-a-form-rather-than-having-to-specify-what
我有一个现有的 HTML

表单,我正在尝试更新以使用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
    }
});

见: http://api.jquery.com/jQuery.ajax/

翻译自:https://stackoverflow.com/questions/9318372/jquery-load-to-post-all-elements-of-a-form-rather-than-having-to-specify-what


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Getting Started with C++ Audio Programming for Game Development

Getting Started with C++ Audio Programming for Game Development

David Gouveia

Written specifically to help C++ developers add audio to their games from scratch, this book gives a clear introduction to the concepts and practical application of audio programming using the FMOD li......一起来看看 《Getting Started with C++ Audio Programming for Game Development》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换