json - Skip duplicates upon AJAX requests -


i trying populate table in jsp page json string. ajax script in jsp page:

function getdata() {    $.ajax({         url: 'ajaxtest',         success: function (data) {             response = $.parsejson(data);              $.each(response, function (i, item) {                 $('<tr>').append(                         $('<td>').text(item.id),                         $('<td>').text(item.name),                         $('<td>').text(item.answer),                         $('<td>').text(item.code),                         $('<td>').text(item.created),                         $('<td>').text(item.state)).appendto('#records_table');             });         }     }); } 

interval:

var intervalid = 0; intervalid = setinterval(getdata, 3000); 

controller:

@requestmapping(value = "/ajaxtest", method = requestmethod.get)     public @responsebody     string getanswers() {          list<answer> result1 = answerservice.getanswers();          gson gson = new gson();         string result = gson.tojson(result1);           return result;     } 

as can see retrieving string controller, use in jsp page send request to. in foreach populating table, works. thing is, continues print out items upon each request (3 seconds)

is there way prepend ajax or check if row exists?

edit: when spitting out data with

$('#result').html(data); 

and

<div id="result"></div> 

i following

[{"id":43,"name":"answer 1","answer":"answer of question","code":2260,"created":"jan 23, 2016","state":"locked"},{"id":32,"name":"answer 2","answer":"answer of question 2","code":7940,"created":"jan 13, 2016","state":"active"}] 


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -