• I am trying to save & update custom theme options using ajax to prevent page reload. but ajax always return 0 although I am using die() at the end of the code.

    function.php code

    wp_enqueue_script( 'fw_js', get_template_directory_uri() . '/core/framework/js/script.js', array('jquery'));
    wp_localize_script( 'fw_js', 'shark_ajax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' )));

    ajax code

    jQuery('#zmfw_update_options').click(function(s){
    s.preventDefault();
    window.zmfw_options = jQuery('#shark-options-form').serialize();
    jQuery.ajax({
    type: 'POST',
    url: shark_ajax.ajaxurl,
    data: {
    action: 'zmfw_shark_ajax',
    optdata: 'iam aher'
    },
    success: function(data){alert(data);console.log(data);}
    })// end ajax
    })//end update_options click function

    Process_options.php code

    <?php
    add_action('wp_ajax_zmfw_zmfw_shark_ajax', 'zmfw_shark_ajax');
    add_action('wp_ajax_nopriv_zmfw_shark_ajax', 'zmfw_shark_ajax');
    add_action( 'wp_ajax_zmfw_shark_ajax', 'zmfw_shark_ajax' );
    
    function zmfw_shark_ajax (){
    $update = update_option('zmfw_shark_options', $_POST['optdata']);
    $retrive = get_option('zmfw_shark_options');
    die($retrive);
    }
    ?>

  • The topic ‘Ajax on backend’ is closed to new replies.