I am having a problem where a fetch using POST data which seems to be appending “#0” to a POST item.
The code which invokes the POST function
POST({'family': fn, 'mode': 'no-cors', 'cmd': "ged", 'ged': JSON.stringify(ged)});
The POST function which handles http requests
let POST = async function(args) {
let fd = new FormData();
fd.append('family', localStorage.getItem('family'));
for (const item in args) {
console.log(item + " : " + args[item]);
fd.append(item, args[item]);
}
let response = await fetch('import.php', {method : 'POST', body : fd});
console.log(response);
let txt = await response.text();
console.log(txt);
let reply = $responseObj(txt);
if(reply.json) {
if(reply.json.status === "ok") {
// popup(reply.json.data);
} else {
console.log(txt);
return false;
}
} else {
popup(txt);
return txt;
}
}
I have plonked a console.log to show the items and their values when appending them to the formData object
console log showing the formData items(except the data which is quite large )
family : TEST1
import.js:72 mode : no-cors
import.js:72 cmd : ged
console log showing part of the error message returned by the php file
“data”:“Unknown cmd sent in POST request. cmd: ged#0 {main}”
The php file just runs the cmd through a switch statement and returns an error message when an unknown command is received.
I did wonder if the #0 may be because the cmd item was the first item in the object parameter and the first item added to the formData object so I changed the order of the items with no change.
I have no idea what the cause of this is.
The app was working 12 months or so ago.
