简体   繁体   中英

Sending Array in Ajax request

Anybody here understand who understands more Ajax. I'm not sure how to send a javascript array in an ajax request. Could someone send me an example of how the ajax request would look? I'm trying to to grab all the javascript data, bundle it into a container and send it per ajax request to coldfusion but I don't understand much ajax so everything would help me.

Thank you for all the answers.

Example using axios library to send array of data in ajax request.

import axios from "axios"
async function sendJavascriptArrayData() {
  const postRequestData = {
    arrayOfStrings: ["react", "svelte", "solidjs"],
    arrayOfNumbers: [1, 2, 3],
  }

  try {
    const res = await axios.post("https://example.com", postRequestData)
    console.log(res.data)

  } catch (error) {
    console.log(error.response)
  }
}

要通过请求发送数组 javascript,您可以通过 JSON.stringify(array) 对其进行字符串化(将其转换为纯文本)并发送。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM