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 {;
}

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

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.