访问 jQuery AJAX 数组中的数据

问题描述 投票:0回答:0

我正在用 PHP 将数组发送到 jQuery AJAX,我想知道如何访问数组键?

我是这样用php发送的

   $json_data = array(
        'message' => $message,
        'user_exist' => $user_exist
    );

    $json_data = json_encode($json_data);

    if ($result->updates->updatedRows == 1) {
        //echo "Success";
        wp_send_json_success( "Succesfull: " . $json_data );
    } else {
        wp_send_json_error( $json_data );
    }

在 AJAX 方面:

success: function(response) {
                var returnedData = JSON.parse(response);
                console.log(returnedData.success);
                                console.log(returnedData);
                console.log(returnedData.data);
                
                


                if (returnedData.success) {
                    $(".success_msg").css('color', 'green');
                } else {
                    $(".success_msg").css('color', 'red');
                }

                $(".success_msg").css("display", "block");
                $(".success_msg").text(returnedData.data);
                
                //setTimeout(function(){ window.location = "http://localhost/calc/thank-you/"; }, 1000);


            },

但似乎我无法接收此数组数据作为消息和用户退出布尔值。

感谢您的帮助enter image description here

php jquery ajax wordpress ajaxform
© www.soinside.com 2019 - 2024. All rights reserved.