javascript - 如何在ajax中插入数组?

标签 javascript jquery postman

我有模式,模式内有一个表单,当我单击提交按钮时,它会执行此操作。

jquery 代码:

  $('#add-new-content-form').on('submit', e => {
    e.preventDefault();
    
    //I want to add this block dates to the data
    let blockdates = $("#block-dates").val();

    let title = $("#card-title").val();
    let catalogId = $("#catalog").val();
    let categoryId = $("#category").val();
    let subcategoryId = $('#subcategory').val();
    let why = $("#why").val();
    let description = $('#card-description').val();
    let cancellationPolicy = $('#cancellation-policy').val();
    let displayPrice = $('#display-price').val();
    let displayDiscounted = $('#discounted-price').val();
    let displayMaxPax = $('#display-maxpax').val();
    let data = {
      "blockDates":[
                 { 
		          "description": "national araw ng mga puso day!",
		          "notAvailableDate": "2019-02-14 10:00:00"
	             },
	             { 
		          "description": "chinese new year!",
		          "notAvailableDate": "2019-02-25 10:00:00"
	             }
               ],
      "title": title,
      "catalogId": catalogId,
      "categoryId": categoryId,
      "subcategoryId": subcategoryId,
      "why": why,
      "description": description,
      "cancellationPolicy": cancellationPolicy,
      "displayPrice": displayPrice,
      "displayDiscounted": displayDiscounted,
      "displayMaxPax": displayMaxPax
    };
     let content = ajax("api/unitContents", JSON.stringify(data), "POST");
    // window.location.replace("/category");
  });

现在, postman 中有这样的东西:

{   
"blockDates":[ 
    { 
        "description": "national araw ng mga puso day!",
        "notAvailableDate": "2019-02-14 10:00:00"
    },
    { 
        "description": "chinese new year!",
        "notAvailableDate": "2019-02-25 10:00:00"
    }
],
"location":{
    "identifier":"UBZ190asas11",
    "name": "abulalas,purok 4",
    "address" : "abulalas1 hagonoy bulacan",
    "lat" : 12141.00,
    "lng" : 123251.00
},
"units": 2,
"title": "sample unit content",
"catalogId": 6,
"categoryId": 22,
"subcategoryId": 13,
"contentOptions": [ 
     {
        "name":"bannana boat",
        "maxPax":8,
        "isAvailableDayTime":[
            9,10,11,12,13,15,16,17,18,
            33,34,35,36,37,39,38,39,40,
            56,57,58,59,60,62,63,64,65,
            80,81,82,83,84,86,87,88,89,
            104,105,106,107,108,110,111,112,113,
            128,129,130,131,132,134,135,136,137,
            152,153,154,155,156,158,159,160,161
        ],
        "inventoryNeededSet":[
            {
            "inventoryId": 1,
            "count":1
            },
            {
            "inventoryId": 1,
            "count":2
            }
        ],
        "paxPrices": [
            {
                "count": 5,
                "pricePerPax": 200,
                "totalPrice": 1000,
                "fee": 100
            },
            {
                "count": 1,
                "pricePerPax": 200,
                "totalPrice": 200,
                "fee": 10
            }
        ]
     },
     {
        "name":"bannana with island tour",
        "maxPax":10,
        "isAvailableDayTime":[
            9,10,11,12,13,15,16,17,18,
            33,34,35,36,37,39,38,39,40,
            56,57,58,59,60,62,63,64,65,
            80,81,82,83,84,86,87,88,89,
            104,105,106,107,108,110,111,112,113,
            128,129,130,131,132,134,135,136,137,
            152,153,154,155,156,158,159,160,161
        ],
        "inventoryNeededSet":[
            {
            "inventoryId": 1,
            "count":2
            },
            {
            "inventoryId": 1,
            "count":2
            }
        ],
        "paxPrices": [
            {
                "count": 5,
                "pricePerPax": 200,
                "totalPrice": 1000,
                "fee": 100
            },
            {
                "count": 1,
                "pricePerPax": 200,
                "totalPrice": 200,
                "fee": 10
            }
        ]
     }

],
"photos": [
    "https://samplephoto1.com",
    "https://samplephoto2.com",
    "https://samplephoto3.com"
],
"videos": [
    "https://samplevid1.com",
    "https://samplevid2.com",
    "https://samplevid3.com"
],
"why": "sample why",
"description": "sample desc",
"cancellationPolicy":"cancellationPolicy",
"displayPrice": 300,
"displayDiscounted": 250,
"displayMaxPax": 2

}

问题是,我想保存区 block 日期,插入区 block 日期的语法是什么?

========================已更新======================

最佳答案

在对数据变量进行字符串化之前尝试此操作:

data.blockdates = $("#block-dates").val();

关于javascript - 如何在ajax中插入数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54434242/

相关文章:

javascript - 什么是 strophe 以及如何将它与 JQuery 一起使用?

api - 如何在 MAC 中设置 NODE_TLS_REJECT_UNAUTHORIZED =0 的值

docker - DNS 在两个链接的 docker 容器之间不起作用 - getaddrinfo EAI_AGAIN 错误

graphql - Postman GraphQL Beta 是否支持订阅

javascript - jQuery UI - 切换幻灯片从右上角出现

javascript - 窗口变量名

JavaScript 和 Web 服务 WSDL

javascript - 在 HTML/javascript 中获取设备的唯一 token

jquery - 虚拟滚动/分页

jquery - 查找多个div中最长的字符串(同一类)