title: Codeigniter: How to return success/fail message to the user after submitting an ajax form
body: <p>I'm starting to get the hang of Codeigniter, but apparently am missing something here.</p>
  
  <p>I'm not sure how to return data to the user after an ajax form submission.
  Here are the relevant bits of my code, with the question inside:</p>
  
  <p><strong>View:</strong></p>
  
  <pre><code>if (confirm("Are you sure?"))
      {
          var form_data = $('form').serialize();
  
          $.post("&lt;?php echo site_url();?&gt;" + "/products/update_multiple", (form_data),
  // this is what I don't understand: how to populate the variable result with data returned from the model/controller?
             function(result) {
                      $('#myDiv').html(result);
              }
              )
      }
  </code></pre>
  
  <p><strong>Controller</strong>:</p>
  
  <pre><code>function update_multiple()
  {
  
   $this-&gt;load-&gt;model('products_model');
   $this-&gt;products_model-&gt;updateMultiple();
  // What goes here, to grab data from the model and send it back to the ajax caller?
  }
  </code></pre>
  
  <p><strong>Model</strong>:</p>
  
  <pre><code>function updateMultiple()
  {
  // I have a drop down list to select the field to update. The values of the drop down list look like this: "TableName-FieldName". Hence the explode.
  
      $table_field = explode("-",$this-&gt;input-&gt;post('field'));
      $table = $table_field[0];
      $field = $table_field[1];
  
      $data = $this-&gt;input-&gt;post('data');
  
      $rows = explode("\n", $data);
  
      foreach($rows as $key =&gt; $row)
      {
          $values = explode(" ", $row);
          $arr[$key]["code"] = $values[0];
          $arr[$key][$field] = $values[1];
      }
  
  
     if ($this-&gt;db-&gt;update_batch($table, $arr, 'code'))
     {
         // Here is the problem. What should I return here, so that it would be sent back to the calling ajax, to populate the result variable?
     }
  
  }
  </code></pre>