创建一个JSON序列化对象做出$ .postJSON电话 [英] Create a JSON serialized object to make a $.postJSON call
问题描述
我有几个文本输入框HTML表单。提交的数据将被发送到后端系统与AJAX / JSON。 在jQuery的,我这样做,它工作得很好:
I have a HTML form with several text input fields. The submitted data will be sent to a backend system with AJAX / JSON. In jQuery, I do this, which works fine:
$("#addPerson").submit(function() {
var person = $(this).serializeObject();
$.postJSON("person/add/", person, function(data) {
...
});
});
现在我有问题,我没有一个形式,但我也想补充一个人。
我有值:姓=蒂姆·
,姓氏=史密斯
,地址=一个街头数量
...
Now I have the problem, that I do not have a form, but I also want to add a person.
I have the values: firstname = Tim
, lastname = Smith
, address = a street with number
, ...
但我怎么可以创建键值对,所以我也有同样类似的行变种人= $(本).serializeObject();
提交的形成我可以用 $打来的电话。postJSON
?
But how can I create the key-value pairs, so I have the same like the line var person = $(this).serializeObject();
submitted by a form and I can make a call with $.postJSON
?
感谢您提前和放大器;最好的问候,蒂姆。
Thank you in advance & Best Regards, Tim.
推荐答案
JSON对象应该是这样的......我想,这就是你要找的内容。
The json object would look like this... I think this is what you're looking for.
var first,
last,
addr;
var jsonObj = {
firstname: first,
lastname: last,
address: addr
}
这篇关于创建一个JSON序列化对象做出$ .postJSON电话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!