I want to save data using ajax. But AJAX callback function replace method not working ? why? THIS MY CODE:

function form_test_permission() {
    return array(
        'submit_form_test' =&gt; array(
            'title' =&gt; t('Submit_form_test'),
            'description' =&gt; t('Submit the form_test form'),
        ),
    );
}

function form_test_menu() {
    $items = array();
    $items['production'] = array(
        'title' =&gt; 'Production',
        'type' =&gt; MENU_NORMAL_ITEM,
        'access arguments' =&gt; array('submit_form_test'),
        'page callback' =&gt; 'drupal_get_form',
        'page arguments' =&gt; array('form_test_form'),
    );

    return $items;
}

function form_test_form($form, &amp;$form_state) {
    $form['production'] = array(
        '#title' =&gt; t('production'),
        '#type' =&gt; 'hidden',
        '#value' =&gt; '1',
    );
    $form['production1'] = array(
        '#title' =&gt; t('production1'),
        '#type' =&gt; 'hidden',
    );

    $form['production_date'] = array(
        '#title' =&gt; t('production_date'),
        '#type' =&gt; 'hidden',
        '#value' =&gt; date('Y-m-d'),
    );
    $form['production_time'] = array(
        '#title' =&gt; t('production_time'),
        '#type' =&gt; 'hidden',
        '#value' =&gt; date('H:i:s'),
    );
    $form['production23'] = array(
        '#title' =&gt; t('production23'),
        '#type' =&gt; 'hidden',
        '#value' =&gt; '1',
    );


    $form['button2'] = array(
        '#value' =&gt; 'UNDO',
        '#type' =&gt; 'submit',
        '#prefix' =&gt; '&lt;div  class="test"&gt;',
        '#suffix' =&gt; '&lt;/div&gt;',
        '#submit' =&gt; array('form_test_form_button2'),
    );

    $form['button1'] = array(
    '#value' =&gt; '  ADD  ',
    '#type' =&gt; 'submit',
    '#prefix' =&gt; '&lt;div  class="test1"&gt;',
    '#suffix' =&gt; '&lt;/div&gt;',
    '#submit' =&gt; array('form_test_form_button1'),
    '#ajax' =&gt; array(
        'callback' =&gt; 'ajax_example_submit_driven_callback',
        'method' =&gt; 'replace',
        'effect' =&gt; 'fade',
        'event' =&gt; 'click',
        'wrapper' =&gt; 'countvalue',
        )
    );
    return $form;
}

function ajax_example_submit_driven_callback($form, $form_state) {
    $result = db_query("SELECT * FROM  form_test WHERE production_date='2014-02-10' and production_time between '01:00:00' and '02:00:00'");
    $prod_1 = $result-&gt;rowcount();
    $form['#tree'] = TRUE;
    $form_state['rebuild'] = TRUE;
    return 'count value is:' . $prod_1 . '';
}

function form_test_form_button1($form, &amp;$form_state) {

    $ft_id = db_insert('form_test')
        -&gt;fields(array(
            'production' =&gt; $form_state['values']['production'],
            'production_date' =&gt; $form_state['values']['production_date'],
            'production_time' =&gt; $form_state['values']['production_time'],
            'production1' =&gt; $form_state['values']['production1'],
        ))
        -&gt;execute();
    $form_state['rebuild'] = true;
}


I have to mentioned in wrapper id in page.tpl.php file.

i want to save data using ajax. But i wrote query in AJAX callback function. AJAX Append method is worked fine. But  AJAX replace function not working ? why?
Fun issue here.  I pulled your code out and stuffed it into a test module and the ajax appeared to work once, eg, on first click of the ADD button, it replaced the &lt;div id="countvalue"&gt;foo&lt;/foo&gt; I had also stuffed into my page.tpl.php.  But then each successive click put up the throbber without any further apparent change.  Throwing a watchdog() into the callback showed it was indeed being called upon each click and then the voila moment:

return '&lt;div id="countvalue"&gt;count value is:' . $prod_1 . '&lt;/div&gt;';


is needed because it was replacing the original &lt;div id="countvalue"&gt; with just the count value is.... text, and then when clicked again, the DOM no longer contained a #countvalue for it to replace again :)