I have code, which get json file from server and then render some if its elements on the page. In this code i also skip items with duplicate value of key “points”. My question is, how do i make these skipped items to store somewhere, so if i click on item that has duplicate, it would link me to some other page with list of these duplicates?
Here is my code
var request = $.ajax({
type: "GET",
url: "example.com/rewards.json"
dataType: "json",
error: function (data, textStatus){
console.log( "it`s error" );
console.log( status );
console.log( data );},
success: function (data, textStatus){
console.log( "success" );
console.log( status );
console.log( data );
}
})
request.success(function(data, textStatus){
var lis = "";
var arr = [];
var iter = 0;
$.each(data.rewards, function(key, val){
if ($.inArray(val.points, arr) == -1)
{
lis += "<div class = 'ui-block-" + String.fromCharCode(97 + iter%3) + "'><a href ='#' class ='ui-link-inherit'>" + val.points + "</a></div>";
arr.push(val.points);
iter += 1;
}
});
$("#rewards_table").html(lis);
})
Description of what i want might be a little confusable, so feel free to ask me anything
You just do exactly that: Store them somewhere for use later.
For example, put this line at the top of your code:
…and add this
elseto theifinside your$.eachiterator function:(I think I got your bracing style right there, a bit alien to me. 🙂 )
The above assumes all of your code is held in some kind of containing function, to avoid creating globals, and so
duplicates(like your existingrequestvariable) won’t end up becoming a global.