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.
CodePudding user response:
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)
}
}
CodePudding user response:
to send an array javascript through a request you can stringify it ( transform it into plain text) via the JSON.stringify(array) and send it.