title: Code igniter show div else show a different div in a view
body: <p>I want to set a divs in conditions IN my View but I don't know how to I do it.If the request from controller comes true to him then success div appear otherwise failure div. At the time I am just printing true and false in alert boxes. 
  Here is my View:</p>
  
  <pre><code>             &lt;div class = "success"&gt;operation done successfully &lt;/div&gt;
               &lt;div class = "failiour"&gt;operation done successfully &lt;/div&gt;
     //these are the two divs on which i want to apply a condition
  
      &lt;form&gt;
  
  
  
               &lt;/form&gt;        
  
         &lt;script type="text/javascript"&gt;
          $('#btn').click(function() { //  $("#form").serialize()
  
  var item_name = $('#item_name').val();
  var cat_id = $('#selsear').val();
  
  if (!item_name || item_name == 'Name') {
      alert('Please enter Category Name');
      return false;
  }
  
  var form_data = {
          item_name: $('#item_name').val(),
          cat_id:    $('#selsear').val(),
  
  
  };
  
  $.ajax({
      url: "&lt;?php echo site_url('itemsController/additems'); ?&gt;",
      type: 'POST',
      data: form_data,
      dataType: 'json',
      success: function(msg) {
          if(msg.res  == 1)
          {
              alert(true);
          }
          else{
           alert(false);             
            }
  
  
      }
  });
  
  return false;
        });
  
  
      &lt;/script&gt;
  </code></pre>
  
  <p>my controller</p>
  
  <pre><code>     function additems(){
  
      //getting parameters from view 
      $data = array(
              'item_name' =&gt; $this-&gt;input-&gt;post('item_name'),
              'cat_id' =&gt; $this-&gt;input-&gt;post('cat_id')
  
      );
  
  
      //$is_ajax = $this-&gt;input-&gt;post('ajax'); //or use this line
      //$this-&gt;input-&gt;is_ajax_request();
  
  
  
  $result = array();
  $this-&gt;load-&gt;model('itemsModel'); 
  $query = $this-&gt;itemsModel-&gt;addItemstoDB($data);
  
  if ($query){  //&amp;&amp; any other condition
  
      $result['res'] = 1;//process successful - replace 1 with any message
  }
  else 
   {
      $result['res'] = 0;//process failed - replace 0 with any message
   }
   echo  json_encode($result);//at the end of the function.
  }
  
  
  
     }
  </code></pre>