JSFiddle - React, Tailwind, and code Playground
AJAX linked list
by Terry King
HTML
<button id="prev">Previous</button>
<button id="next">Next</button>
<div id="results"></div>
JavaScript
var imageno = 0
var current
var start
var locked = false
GetTrio()
$('#prev').click(function () {
if (current.prev && !locked) {
current = current.prev
GetPrev(current, 3)
Display()
}
});
$('#next').click(function () {
if (current.next && !locked) {
current = current.next
GetNext(current, 3)
Display()
}
});
function GetPrev(pobj, count) {
locked = true
var actualCount = count
var first = pobj
first.loading = true
while (first.prev && actualCount > 0) {
first = first.prev
first.loading = true
actualCount--
}
if (actualCount > 0) {
var data = '{'
for (i = 0; i < actualCount; i++) {
data += '"prev' + (i + 1) + '_filename" : "image' + (imageno + i) + '.jpg",'
data += '"prev' + (i + 1) + '_width" : 500,'
data += '"prev' + (i + 1) + '_height" : 900'
if (i < actualCount - 1) {
data += ','
}
}
imageno += actualCount
imageno = imageno % 10
data += '}'
data = {
json: data,
delay:0
}
$.ajax({
url: '/echo/json/',
type: 'POST',
data: data,
success: function (response) {
for (i = 0; i < actualCount; i++) {
if (eval('response.prev' + (i + 1) + '_filename') != start.filename) {
p = new Object()
p.filename = eval('response.prev' + (i + 1) + '_filename')
p.width = eval('response.prev' + (i + 1) + '_width')
p.height = eval('response.prev' + (i + 1) + '_height')
p.next = first
first.prev = p
first = first.prev
imageLoad(p)
} else {
first.prev = start
start.next...