How to run an ajax call in elementor editor

Question

I am having a strange issue. I am not able to execute an ajax call while in Elementor edit mode.

add_action( 'wp_ajax_slug_configureheader', [ $this, 'rename_configureheader_callback' ] );
add_action( 'wp_ajax_nopriv_slug_configureheader', [ $this, 'rename_configureheader_callback' ] );

and I have a callback function like this

public function rename_configureheader_callback(){
      // there is code in in here
        // post id is from ajax
      update_post_meta($post_id, 'car_model', 157 );
      echo "Hello";
      die;
    }

even though I specified the callback function to be this

 //console.log(renameDataheader);
    $.ajax({
      url: slug.ajax_url,
      type: 'POST',
      data: {
        action: slug.ajaxaction, //slug_configureheader
        nonce: slug.nonce,
        idofpost: slug.pageid,
      },
      success: function(response) {
        alert("Success");
        console.log(response);
        // $('#output').append(response);
      },
    });

I get the alert-success but the callback function never executes. How Elementor prevents the callback function? I am stuck on this for the past two days pls help

0
Latheesh V M Villa 3 months 0 Answers 7 views 0

Leave an answer