追加变量以将其发布到ajax序列化数据 [英] append variable to be posted to ajax serialized data
本文介绍了追加变量以将其发布到ajax序列化数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表单,可以像这样在ajax调用中发布所有数据:
I have a form that I can post all the data in the ajax call like this:
data: $("#myform).serialize(),
但是在函数中,我设置了一个要发布的变量
But in the function, I set a variable to be be posted
该变量为var favorite = true;或var favorite = false;
That variable is var favorite = true; or var favorite = false;
如果执行此操作,它将发布该变量:
It will post that variable if I do this:
var favorite = true;
var first_name = $("myform input[name=first_name]").val();
data: { favorite: favorite, first_name: first_name, etc ... }
但是我想知道我是否可以像这样:
But I was wondering if i could something like:
data: $("#myform).serialize + {favorite: favorite}
如果那不可能的话没什么大不了的,我只是清理函数.
Its not a big deal if thats not possible, I am just clean up the function.
推荐答案
serialize()
方法返回参数字符串,因此您可以像这样使用字符串连接
The serialize()
method return a parameter string, so you could just use string concatenation like
data: $("#myform").serialize() + '&favorite=' + favorite
这篇关于追加变量以将其发布到ajax序列化数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文