Ajax call always successful and returns 0

I have look through all other threads regarding this. But none of them works.

My ajax call:

    //update database with posted values
function updateDB(name, email, address, co_address, city){
        url: '/wp-admin/admin-ajax.php',
        type: 'POST',
        dataType: 'json',
        data: {
            action: 'det_lilla_extra',
            //pictureURL: picUrl,
            name: name,
            email: email,
            address: address,
            co_address: co_address,
            city: city
        success: function (data) {
            console.log("success: " + data);
        error: function (data) {
            console.log("fail: " + data);

My action hook:

add_action('wp_ajax_det_lilla_extra', 'det_lilla_extra');
add_action( 'wp_ajax_nopriv_det_lilla_extra', 'det_lilla_extra' );
function det_lilla_extra(){

    echo json_encode($_POST);

    global $wpdb;

    // If validation has no errors, insert data
    if ( $wpdb->insert('fellotest.orders',
            'picUrl' => $_POST['picURL'],
            'name' => $_POST['name'],
            'email' => $_POST['email'],
            'address' => $_POST['address'],
            'co_address' => $_POST['co_address'],
            'city' => $_POST['city']
    )) {
        // If $wpdb->insert was successful, send success message back to AJAX updateDB function
        wp_send_json_success(array('message' => 'Successfully uploaded!'));

    } else {
        // If insert was unsuccessfull, send error message back to AJAX
        wp_send_json_error(array('message' => 'Error: Something went wrong'));



I have commented out my functionality for now..

I dont understand why I dont get any data back?

Read more here: Ajax call always successful and returns 0

Leave a Reply

Your email address will not be published. Required fields are marked *