• I am attempting to post a JSON encoded string to the server using XMLHttpRequest and admin-post.php. This string is quite long representing about 80 fields on a DB record edit screen. I append three fields to the formdata object. I get the data for two of them but the one that is supposed to hold the JSON encoded string will is not received at admin-post.php. It just is null. I can see in the debugger that the string is being sent but cannot for the life of me figure out where it goes. I am also having problems doing a regular post of the form as well.

    Here is the Javascript part:

    function dbSaveOnClick(e) {
        
        var formData    = new FormData();
        var dbRequest   = new XMLHttpRequest();
        var data        = {};
        var postobj     = "";
        var recordId    = 0;
        
    
        for(a=0;a<document.getElementById('dbForm').elements.length;a++) {
            switch(document.getElementById('dbForm').elements[a].id) {
                case "dbAttributes":
                case "dbSave":
                case "dbCancel":
                case "dbNULL":
                case "":
                    break;
                default:
                    data[document.getElementById('dbForm').elements[a].id] = document.getElementById('dbForm').elements[a].value;
                    break;
            }   
        }
        
        postobj = JSON.stringify(data);
        
        formData.append("action", "upload_form_data");
        formData.append("id", recordId);
        formData.append("fielddata", postobj);
        
        dbRequest.onreadystatechange = dbSaveOnReadyStateChange;
        dbRequest.open('POST', "/wp-admin/admin-post.php", true);
        dbRequest.send(formData);
    
    }
    • This topic was modified 7 years, 11 months ago by bcworkz. Reason: code fixed
Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Do you have any idea how many bytes the string uses? Max. string lengths are very generous, so that shouldn’t be a problem, but everything else appears to be in order. Try truncating the data string to a small subset just to see if the length really is the issue. It can be malformed, the idea is to confirm if it comes through, not to parse it.

    Is there any sort of security running on the server? It could be set to discard very long data streams. If the smaller string does not come through, please post your handler function. Since it may be very long, I’m only interested in how the data is collected and initially assigned, I’m not interested once the script gets past parsing the data and starts doing something with the result. Please use backticks or the code button when posting code here. Failure to do so makes it very annoying to test any part of your code because all the quotes are improper “curly” style. You do not want me to be annoyed ??

    Thread Starter markround

    (@markround)

    Thank you. I will try these things.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘The function admin-post.php not receiving all of the data sent to it.’ is closed to new replies.