$(this).serialize()-如何添加值? [英] $(this).serialize() -- How to add a value?

查看:442
本文介绍了$(this).serialize()-如何添加值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我有以下内容:

$.ajax({
    type: 'POST',
    url: this.action,
    data: $(this).serialize(),
});

这很好,但是我想为数据添加一个值,所以我尝试了

This works fine, however I would like to add a value to data, so I tried

$.ajax({
    type: 'POST',
    url: this.action,
    data: $(this).serialize() + '&=NonFormValue' + NonFormValue,
});

但这并不能正确发布.关于如何将项目添加到序列化字符串的任何想法?这是一个全局页面变量,不是特定于表单的.

But that didn't post correctly. Any ideas on how you can add an item to the serialize string? This is a global page variable that isn't form specific.

推荐答案

代替

 data: $(this).serialize() + '&=NonFormValue' + NonFormValue,

您可能想要

 data: $(this).serialize() + '&NonFormValue=' + NonFormValue,

如果NonFormValue的值可能包含任何特殊字符,则应谨慎使用URL编码.

You should be careful to URL-encode the value of NonFormValue if it might contain any special characters.

这篇关于$(this).serialize()-如何添加值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆