title: Laravel 5.3 : Auto refresh div when data update with Ajax
body: <p>I code auto refresh div with ajax every second, but i want auto refresh div just if data change not every second. What the better way?</p>
  
  <p>Javascript</p>
  
  <pre><code>&lt;script&gt;
    setInterval(function(){
     $('#datapinjam').load('/datarealtime');
   }, 30000)
  &lt;/script&gt;
  </code></pre>
  
  <p>Blade code</p>
  
  <pre><code>&lt;div class="table-responsive mt-3"&gt;
    &lt;table id="basic-datatable" class="table dt-responsive nowrap"&gt;
        &lt;thead&gt;
            &lt;tr&gt;
              &lt;th&gt;ID&lt;/th&gt;
              &lt;th&gt;Inventaris&lt;/th&gt;
              &lt;th&gt;No Handphone&lt;/th&gt;
              &lt;th&gt;Mulai&lt;/th&gt;
              &lt;th&gt;Selesai&lt;/th&gt;
              &lt;th&gt;Tanggal&lt;/th&gt;
              &lt;th&gt;Keperluan&lt;/th&gt;
              &lt;th&gt;Status&lt;/th&gt;
              &lt;th&gt;Action&lt;/th&gt;
            &lt;/tr&gt;
        &lt;/thead&gt;
        &lt;tbody&gt;
            &lt;tr&gt;
              @foreach ($peminjaman as $value)
  
               ....
  
            @endforeach
        &lt;/tbody&gt;
  
  
    &lt;/table&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>Controller code</p>
  
  <pre><code>public function realtime()
  {
    $data['peminjaman'] = DB::table('data_peminjaman')
                          -&gt;join('inventaris', 'data_peminjaman.id_invetaris', '=', 'inventaris.id')
                          -&gt;orderBy('data_peminjaman.iid','desc')
                          -&gt;paginate(10);
    return view('admin.realtime',$data);                      
  }
  </code></pre>