jeudi 2 juillet 2015

Getting 304 Error in response of jquery request

Scenario:

  1. User visit the page

  2. Jquery started to make ajax request to backend code

  3. Navigate to page (not refreshing) I can see the request still going to server from client. It supposed to be stopped now.
  4. When user return to same page again, Request should started to hit but it's throwing 304 error. Jquery supposed to hit the request again.

User click on following button code

index.html.erb

<td colspan="3"><%= link_to 'Show state', simulation, :class => 'btn btn-primary' %></td>

will navigate to

show.html.erb

Here I have written the jquery code to making Ajax request

<script>
$(function() {setInterval(function(){ $.get("/posts/<%= @post.id %>"); }, 5000);
});

Dom needed to be changes after every `Ajax` response in same views (show.html.erb)

<span id="post-data">
  <table class = 'table table-hover'>
     .....
  </table>
</span>

js file for rendering the views

in show.js.erb

$("#post-data").html(" <table> ... </table>") 

How can I fix these errors. Any help would be appreciable, I am not a core javascript guy.

Aucun commentaire:

Enregistrer un commentaire