【问题标题】:Colorbox - how to set data property to use POST instead of GETColorbox - 如何设置数据属性以使用 POST 而不是 GET
【发布时间】:2011-06-28 09:47:27
【问题描述】:

我正在使用 colorbox 插件,根据文档,data 属性允许通过 ajax 请求提交 GET 或 POST 值。我可以通过 GET 提交我的数据没问题,但不知道如何切换到 POST。我正在使用序列化将表单数据设置为名称/值对。我有以下代码:

有没有办法将其设置为 POST?

var data = $('form').serialize();

            console.log(data);

            // Preview newsletter - bind colorbox to event
            $('a#preview').colorbox({
                width: '670px',
                href: $(this).attr('href'),
                data: data
            });

            return false;
        });

【问题讨论】:

  • @Vivek Goel - 啊,我明白了,好的,我目前正在将数据作为键/值对传递,例如 intro=&proj=7,这如何转化为对象?
  • from.serialize 给你字符串。要么将其转换为对象。

标签: jquery ajax jquery-plugins colorbox


【解决方案1】:

使用

 $('form').serializeArray();

【讨论】:

    【解决方案2】:

    data 属性的行为与 jQuery 的 .load() 数据参数完全相同,因为 ColorBox 使用 .load() 进行 ajax 处理。

    【讨论】:

    • 你能举个例子吗?
    猜你喜欢
    • 2020-10-18
    • 1970-01-01
    • 2017-11-27
    • 2011-08-04
    • 2010-09-07
    • 1970-01-01
    • 2016-12-25
    相关资源
    最近更新 更多