Site icon Hip-Hop Website Design and Development

Move worth by way of Ajax on onchange

Im attempting to know cross a price from a dropdown at a onChange state. Whats the perfect observe for this?

Kind:

<choose id="dropdown_shop_order_language" title="wcml_shop_order_language">
 <possibility worth="nl" chosen="selected">Niederländisch</possibility>
 <possibility worth="en">Englisch</possibility>
 <possibility worth="de">Deutsch</possibility>
</choose>

My script thus far:


jQuery(doc).prepared(operate () {

    jQuery('#dropdown_shop_order_language').change(operate () {
    alert("Whyunoalert?");
    jQuery.ajax(
    {
        sort: "post",
        url: "/wp-admin/admin-ajax.php",
        knowledge: {"dropdown_shop_order_language": jQuery('#dropdown_shop_order_language').val()}, 
        success: operate(knowledge){
            console.log(knowledge);
        }
    });
      });
 });     

Operate:

operate my_enque_action( $hook ) {

    international $put up;
     $postid = $post->ID;  
    if ( $hook == 'post-new.php' || $hook == 'put up.php' ) {
        
        if( get_post_type( $postid ) === 'shop_order' ) {  
         wp_enqueue_script( 'lang_script', get_template_directory_uri() . '/belongings/javascripts/language.js', array( 'jquery' ), '1.0.0', true );
         wp_localize_script( 'ajax-script', 'my_ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
                

        }
    }
}
add_action( 'admin_enqueue_scripts', 'my_enque_action', 10, 1 );



operate my_action( ) {
    $dropdown_shop_order_language = $_POST['dropdown_shop_order_language'];
    echo $dropdown_shop_order_language;
    if ( $dropdown_shop_order_language == 'en' ) {
     alert("language is en");
    } elseif ( my_action() == 'nl' ) {
    alert("language is nl");
    } elseif ( my_action() == 'de' ) {
    alert("language is nl");
    } else {
    alert("language is none");
    }
      
}
add_action( 'wp_ajax_my_action', 'my_action' );
add_action( 'wp_ajax_nopriv_my_action', 'my_action' );