Answer the question
In order to leave comments, you need to log in
How to use the script once instead of pasting it every time?
I have a script:
$.getJSON('/js/db04.json', function (data) {
$(data).each(function(index, item) {
$('#table').append(
'<tr><td class="col1">'+ item.title01 +'</td><td class="col2">' + item.shopcode + '</td><td> <a href="' + item.link + '">' + item.title + '</a></td><td class="col3">' + item.cost + '</td></tr>'
);
});
});
Answer the question
In order to leave comments, you need to log in
Take it to a separate function and pass the necessary parameters, which can change from call to call as arguments.
function getJsonAndUpdateTable(jsonPath) {
$.getJSON(jsonPath, function (data) {
$(data).each(function(index, item) {
$('#table').append(
'<tr><td class="col1">'+ item.title01 +'</td><td class="col2">' + item.shopcode + '</td><td> <a href="' + item.link + '">' + item.title + '</a></td><td class="col3">' + item.cost + '</td></tr>'
);
});
});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question