0

This's my code it's success but when but I can't the return data from ajax in the same page. the mechanism is the user click the dropbox button and when he selects it returns dropbox_links and then insert dropbox_links in database using add_post_meta

The Insert should be on the spot becuase the dropbox button click is the only trigger

 $.ajax({
    
                type: "POST",
                data: {
                    req: JSON.stringify(dropbox_links)
                },
    
                cache: false,
                success: function(responseData) {
                    // consider using console.log for these kind of things.
                    console.log("Data recived: " + responseData);
                    console.log(dropbox_links);
    
                },
                error: function(msg) {
                    console.log("not sure what to ask for here to check issue" + msg);
                }
            });

This's the php code but I don't catch or print any data so should I re-run the whole php script to see if it returns any data?

function printdata()
{
    $data    = $_POST["req"];
    $data    = json_decode($data, true);
    print_r($data);
}

if (isset($POST["req"])) {

    printdata();
} else {;
}
New contributor
Steve is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

1 Answer 1

0

You have to use json_encode to return data. Also use $_POST instead of $POST.

Please try the following code for the PHP part.

function printdata() {
    $data = $_POST["req"];
    echo json_encode($data);
}

if (isset($_POST["req"])) {
    printdata();
} else {
    echo 'No Data';
}

Your Answer

Steve is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.