title: Drupal 7 FAPI - ajax image preview
body: <p>I am trying to preview the uploaded image using ajax in my D7 module but don't know why it's not working. Here is what I am trying to do:-</p>
  
  <pre><code>function create_ad_form($form, &amp;$form_state)
  {
     $form['image_file'] = array(
         '#title' =&gt; t('Upload Banner:'),
         '#type' =&gt; 'file',
     );
  
     $form['submit'] = array(
         '#type' =&gt; 'submit',
         '#value' =&gt; 'Submit',
         '#submit' =&gt; array('create_ad_form_submit'),
         '#ajax'=&gt; array(
            'callback'=&gt;'create_ad_form_submit',
            'wrapper'=&gt; 'im-area',
            'method'=&gt; 'replace',
            'effect'=&gt; 'fade',
         )
     );
  
     $form['im-container']=array(
         '#prefix'=&gt;'&lt;div id="im-area"&gt;',
         '#suffix'=&gt;'&lt;/div&gt;',
     );
  }
  
  function create_ad_form_submit($form, $form_state)
  {
     $file = file_save_upload('image_file', array(), "public://",$replace = FILE_EXISTS_REPLACE);
     if ($file)
     {
         $file-&gt;status=FILE_STATUS_PERMANENT;
         file_save($file);
         $form['im-container']=array(
               '#title'=&gt;t('Preview:'),
               '#prefix'=&gt;'&lt;div id="im-area"&gt;',
               '#markup'=&gt;'&lt;img src="sites/default/files/'.$file-&gt;filename.'"&gt;',
               '#suffix'=&gt;'&lt;/div&gt;',
         );
     }
     else
         drupal_set_message('No file uploaded.');
  
     return $form['im-container'];
  }
  </code></pre>
  
  <p>The above code gives no error but the image preview doesn't show up. Can anybody tell what I am doing wrong here and what should I do??? Thanks.</p>