Plugins – WordPress Ajax Success does not return value

I have created a plugin where I am getting data through rest url and when I use var_dump($final_price_return) I am getting correct output; and no return in success call. PHP code that returns the value:

function handle_query($data) {
    // Handle the form data that is posted
    // Get all parameters from form
    $output = $data->get_params();

    // Check if nonce is valid, if not, respond back with error
    if (!wp_verify_nonce($output['_wpnonce'], 'wp_rest')) {
        return new WP_Rest_Response('Oops - Invalid request', 422);

    // done calculations here - skipped that code for now

    return new WP_REST_Response($final_price_return, 200);

JQuery code

jQuery(document).ready(function () {
        $('#calx').on('click', function (e) {
            rules: {
              // simple rule, converted to {required:true}
              service: 'required',
              square_feet: 'required',
            messages: {
              service: 'Please select service',
              square_feet: 'Please select your square feet area',
            submitHandler: function () {
              var formData = $('#msform').serialize()
                url: "<?php echo get_rest_url(null, 'bohio/v1/submit'); ?>",
                type: 'POST',
                data: formData,
                cache: false,
                success: function (res) {

Leave a Comment