如果我的jQuery的序列化發佈如下:你如何選擇你用jquery序列化的json信息?
{"PurchaseOrders":[{"Id":"8a4c70a63db7b320013dc35247960095","Version":124,"Context":{"RealmId":"1","CustomerId":"111","ProjectId":"2222","Operation":null}
如何排除
{"PurchaseOrders":[
從我的職務,同時還提交一切它包含?
我目前使用這個劇本,我的系列化: https://github.com/tlowrimore/jquery.serialize-object/blob/master/jquery.serialize-object.js
(function($) {
var methods = {
setValue: function(path, value, obj) {
if(path.length) {
var attr = path.shift();
if(attr) {
obj[attr] = methods.setValue(path, value, obj[attr] || {});
return obj;
} else {
if(obj.push) {
obj.push(value);
return obj;
} else {
return [value];
}
}
} else {
return value;
}
}
};
$.fn.serializeObject2 = function() {
var obj = {},
params = this.serializeArray(),
path = null;
$.each(params, function() {
path = this.name.replace(/\]/g, "").split(/\[/);
methods.setValue(path, this.value, obj);
});
return obj;
};
})(jQuery);
$(document).ready(function() {
$("#btn-add-po-submit").click(function(e) {
e.preventDefault();
var formData = $("#form-add-po").serializeObject2();
var url = $("#form-add-po").attr("action");
console.log(url);
$.ajax({
type: 'POST',
contentType: "application/json",
url: url,
dataType: 'json',
data: JSON.stringify(formData),
error : function(jqXHR, textStatus, errorThrown) {
console.error(textStatus);
},
success : function(data, textStatus, jqXHR) {
console.log(textStatus);
}
});
/*$('#result').text(JSON.stringify($('form').serializeObject()));
return false;*/
});
假設'json'是完整的對象。你不能只通過'json ['PurchaseOrders']'? –
上面的js通過哪裏? – beng
'data:JSON.stringify(formData ['PurchaseOrders']),' –