title: DataTables warning: table id=dataTable - Invalid JSON response. For more information about this error
body: <p>I am geeting below error:
  DataTables warning: table id=dataTable - Invalid JSON response. For more information about this error.</p>
  
  <p>I added create.js.erb file recently to update post in browser without reload. Does that mean, data is getting saved in js format. because when i try to 
  open micropost/show link, its working fine- data is getting loaded. but when i try to open micropost/index link, i get above error.</p>
  
  <p>Before adding create.js.erb file, i had data saved in DB in HTML format. </p>
  
  <p>controller:</p>
  
  <pre><code>def create
  @user = current_user
  @micropost = current_user.microposts.build(micropost_params)
  if @micropost.save
    respond_to do |format|
    format.js
    end
  end
  end
  </code></pre>
  
  <p>create.js.erb</p>
  
  <pre><code>$('#micropost_refresh').prepend("&lt;%= j render @micropost %&gt;");
  $('#micropost_count h3').replaceWith("&lt;h3&gt;Microposts (&lt;%=@user.microposts.count %&gt;)&lt;/h3&gt; ");
  </code></pre>
  
  <p>show.html.erb</p>
  
  <pre><code>&lt;section class="micropost_form"&gt;
  &lt;%=form_for((Micropost.new), :remote =&gt; true, :id =&gt;'new_micropost') do |f| %&gt;
  &lt;div class="field"&gt;
  &lt;%= f.text_area :content, placeholder: "Compose new micropost..." %&gt;
  &lt;/div&gt;
  &lt;%= f.submit "Post", class: "btn btn-primary" %&gt;
  &lt;% end %&gt;   
  &lt;/section&gt;
  &lt;div class="col-md-8"&gt;
    &lt;div id="micropost_count"&gt;
    &lt;% if @user.microposts.any? %&gt;
    &lt;h3&gt;Microposts (&lt;%= @user.microposts.count %&gt;)&lt;/h3&gt;&lt;/div&gt;
    &lt;div id="micropost_refresh"&gt;
    &lt;ol class="microposts"&gt;
    &lt;% @user.microposts.each do |micropost| %&gt;
    &lt;li&gt;   &lt;%= render 'microposts/micropost', micropost: micropost %&gt;&lt;/li&gt; 
    &lt;% end %&gt;
    &lt;/ol&gt;&lt;/div&gt;&lt;% end %&gt;
    &lt;/div&gt;
    &lt;/div&gt;
  </code></pre>
  
  <p>controller:</p>
  
  <pre><code> def index
   @microposts = Micropost.all
    respond_to do |format|
        request.format = "html"
        format.html
       end
    end
  </code></pre>
  
  <p>index.html.erb</p>
  
  <pre><code>&lt;div class="card-body"&gt;
  &lt;div class="table-responsive"&gt;
    &lt;table class="table table-bordered display" id="dataTable" width="100%" cellspacing="0" data-source="&lt;%= microposts_path(current_user, format: "json") %&gt;"&gt;
      &lt;thead&gt;
        &lt;tr&gt;
          &lt;th&gt;Time&lt;/th&gt;
          &lt;% if current_user.admin? %&gt;
          &lt;th&gt;User&lt;/th&gt;
            &lt;th&gt;Phone Number&lt;/th&gt;
          &lt;% end %&gt;
          &lt;th&gt;Event Category&lt;/th&gt;
          &lt;th&gt;Message&lt;/th&gt;
        &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
        &lt;% @microposts.each do |micropost| %&gt;
      &lt;tr&gt;
        &lt;td&gt;&lt;%= micropost.created_at %&gt;&lt;/td&gt;
        &lt;% if current_user.admin? %&gt;
        &lt;td&gt;&lt;%= micropost.user.name %&gt;&lt;/td&gt;
        &lt;td&gt;&lt;%= micropost.user.phone_number %&gt;&lt;/td&gt;
        &lt;% end %&gt;
        &lt;td&gt;&lt;%= micropost.events.pluck(:category_id).first %&gt;&lt;/td&gt;
        &lt;td class="content"&gt;&lt;%= micropost.content %&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;% end %&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>
    </p>
  
  <p>When i post a message, it should automatically update in the page without reloading which it does. But same data is not getting loaded into datatable.
  Please someone help me with this.</p>