title: dynamically validation errors are not displaying and given json response correct
body: <p>Parse error on line 4:</p>
  
  <pre><code>... required.&lt;\/p&gt;\n"}{    "error": "&lt;p&gt;T
  ----------------------^
  Expecting 'EOF', '}', ',', ']'
  </code></pre>
  
  <p>for the below json response:</p>
  
  <pre><code>{
      "st": 0,
      "msg": "&lt;p&gt;The Title field is required.&lt;\/p&gt;\n&lt;p&gt;The Description field is required.&lt;\/p&gt;\n&lt;p&gt;The URL field is required.&lt;\/p&gt;\n&lt;p&gt;The Posted On field is required.&lt;\/p&gt;\n&lt;p&gt;The Expire Date field is required.&lt;\/p&gt;\n"
  }{
      "error": "&lt;p&gt;The upload path does not appear to be valid.&lt;\/p&gt;"
  }
  </code></pre>
  
  <p>Here is my controller file :</p>
  
  <pre><code>public function addnews()
  {
          $userfile = 'userfile';
  
          $this-&gt;load-&gt;library('form_validation');
  
          $this-&gt;form_validation-&gt;set_rules('title', 'Title', 'trim|required|min_length[5]');
          $this-&gt;form_validation-&gt;set_rules('description', 'Description', 'trim|required');
          $this-&gt;form_validation-&gt;set_rules('url', 'URL', 'trim|required');
          $this-&gt;form_validation-&gt;set_rules('userfile', 'Image', 'trim');
          $this-&gt;form_validation-&gt;set_rules('postedon', 'Posted On', 'trim|required');
          $this-&gt;form_validation-&gt;set_rules('source', 'Source','trim|required');
          $this-&gt;form_validation-&gt;set_rules('expiredate', 'Expire Date', 'trim|required');
  
          if($this-&gt;form_validation-&gt;run() == FALSE)
          { 
              echo json_encode(array('st'=&gt;0, 'msg' =&gt; validation_errors())); 
          }
          /******* extracting file extension ********/
          $org_filename = $_FILES['userfile']['name'];
          $path_parts = pathinfo($org_filename);
          //$file_extension = $path_parts['extension'];
          /***** end extracting file extension ******/
  
          $config['upload_path'] = './vadmin/uploads/news';
          $config['allowed_types'] = 'gif|jpg|png';
          $config['max_size'] = 1024 * 1000;       
          //$config['file_name'] = 'news_'.time().'.'.$file_extension;
  
          //echo "&lt;pre&gt;";
          //print_r($_FILES);
  
          $this-&gt;load-&gt;library('upload', $config);
  
          if (!$this-&gt;upload-&gt;do_upload($userfile))
          {
             //echo '&lt;br&gt;entered into upload failed block.. ';
             $error = array('error' =&gt; $this-&gt;upload-&gt;display_errors());
             echo json_encode($error);
          }
  
          else
          {
              /**** assignment of post data ******/
              $title = $this-&gt;input-&gt;post('title');
              $description = $this-&gt;input-&gt;post('description');
              $url = $this-&gt;input-&gt;post('url');
              $userfile = $this-&gt;input-&gt;post('userfile');
              $postedon = $this-&gt;input-&gt;post('postedon');     
              $source = $this-&gt;input-&gt;post('source');
              $expiredate = $this-&gt;input-&gt;post('expiredate');
              $status = $this-&gt;default_news_status ;
              /**** end assignment of post data ******/
  
              /**** load news model to insert reocrd into table *****/
              $this-&gt;load-&gt;model('vadmin/Newsmodel','',true);
              $this-&gt;Newsmodel-&gt;addRequestForm();
              /**** load news model to insert reocrd into table *****/
  
              //print jsone response for ajax request
              echo json_encode(array('st'=&gt;1, 'msg' =&gt; 'Successfully Submitted'));
  
       }
  
  }
  </code></pre>
  
  <p>Here is my view script: </p>
  
  <pre><code>function ajaxFileUpload()
  {
      $.ajaxFileUpload
      (
          {
              url:'&lt;?php echo base_url();?&gt;vadmin/ajax/addnews/',
              secureuri:false,
              fileElementId:'userfile',
              dataType: 'JSON',
              data: {title:$('#title').val(),description:$('#description').val(),url:$('#url').val(),userfile:$('#userfile').val(),postedon:$('#datepicker').val(),source:$('#source').val(),expiredate:$('#datepicker1').val()},
              /*beforeSend:function()
              {
                  $("#loading").show();
              },
              complete:function()
              {
                  $("#loading").hide();
              },  */          
              success: function (data)
              {
                   if(data.st == 0)
                  {
                      $('#message').css('color','red');
                      $('#message').html(data.error).show(400);
                  }
                  if(data.st == 1)
                  {
                      $('#message').css('color','green');
                      $('#message').html(data.msg).show(400);
                  } 
                  if(typeof(data.error) != 'undefined')
                  {
                      if(data.error != '')
                      {
                          alert(data.error);
                      }else
                      {
                          alert(data.msg);
                      }
                  }
              },
              /*error: function (resp, status, e)
              {
                  alert('ajax error :: '+e);
              }  */
          }
      );
  
      return false;
  }
  </code></pre>