发送其他JSON数据以及发送序列化表单数据的现有AJAX帖子

时间:2015-10-11 23:31:24

标签: javascript jquery json ajax

我想发送额外的JSON数据以及现有的AJAX表单帖子。

我有这个AJAX请求,用JavaScript提交HTML表单......

// Serialize the data in the form
var serializedCommentData = $parentCommentForm.serialize();

// Make AJAX Save POST Request
commentAjaxRequest = $.ajax({
    url: ProjectManagementTaskModal.cache.urlEndPointsObj.createTaskCommentReplyUrl,
    type: 'post',
    data: serializedCommentData
});

我还在JavaScript变量中保存了一个JSON字符串......

var jsonString = '[{"id":1,"name":"Kenneth Auchenberg","avatar":"http://cdn0.4dots.com/i/customavatars/avatar7112_1.gif","type":"contact","value":"Kenneth Auchenberg"},{"id":9,"name":"Kenneth Hulthin","avatar":"http://cdn0.4dots.com/i/customavatars/avatar7112_1.gif","type":"contact","value":"Kenneth Hulthin"}]';

如何使var jsonString中的JSON字符串与表单发送的相同AJAX请求一起发送?

1 个答案:

答案 0 :(得分:2)

您可以创建一个包含两个字段的对象

    commentAjaxRequest = $.ajax({
        url: ProjectManagementTaskModal.cache.urlEndPointsObj.createTaskCommentReplyUrl,
        type: 'post',
        data: JSON.stringify(pack)
    });

并序列化然后传递数据。

{{1}}

您需要在接收器脚本中解压缩

相关问题