Fetch using POST, data changed when retrieved in php file

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.

This text is a part of PHP error message, it isn’t related to your data and shows part of stack trace (#0 supposed to be a step number and {main} means that error occurred in the first called file).

Look at this sample error message:

So check that your PHP switch-statement really contains ged case

1 Like

I’m wondering if the ged value, which is different from the other literal string values in the POST(…) call, in that it is shown with double-quotes, didn’t pickup some smart/curly quotes or non-printing characters due to copy/pasting?

Try deleting and retyping all the characters that make up the ‘cmd’: ..., value

Thanks for that insight.
I changed the logic in the php file where testing the POST data and problem solved.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.