I have a code on client-side that is using JavaScript to create an object called "data" that contains several variables such as "matricula", "scheduled", "selectedDate", "selectedChoices", "workshop", and "daySlot". The object is then being converted to a JSON string and sent to a specific URL using an XMLHttpRequest with a "POST" method. Then I have a landing page that is using AMPscript to retrieve the values of the variables that were sent in the previous code using the RequestParameter function. Then it's using the InsertDE function to insert the values into a Data Extension.
The problem is, when I test the code, it is adding an empty row to the Data Extension. Can anyone help me too see what could be the problem here? Thank you!
Client-Side JS code:
const sendData = function() {
var data = {
"matricula": matricula,
"scheduled": scheduled,
"selectedDate": selectedDate,
"daySlot": daySlot,
"selectedChoices": selectedChoices,
"workshop": workshopSelected
};
var xhr = new XMLHttpRequest();
xhr.open("POST", "https://mcwjw68xg1lkqk0bj841tnslyx5y.pub.sfmc-content.com/r5g5qsdldwq");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(JSON.stringify(data));
console.log(JSON.stringify(data));
};
AMPscript code:
%%[
var @insertCount
SET @matricula = RequestParameter("matricula");
SET @selectedDate = RequestParameter("selectedDate");
SET @selectedChoices = RequestParameter("selectedChoices");
SET @workshop = RequestParameter("workshop");
SET @daySlot = RequestParameter("daySlot");
SET @scheduled = RequestParameter("scheduled");
InsertDE("Proactive Maintenance Data", "Matrícula", @matricula, "Agendou", @scheduled, "Data Escolhida", @selectedDate, "Altura do dia", @daySlot, "Razões", @selectedChoices, "Confessionário", @workshop);
]%%