I posted about 10 days ago due to the issue of displaying the Previous Results and Next Results buttons on Gurunabi.
Thanks to Unarist, the problem has been resolved.Thank you.
Now, I want to create the "To" and "To" buttons and click to display the first and last pages, respectively."To the top" is the code below, and it was easy to get the results you wanted.
jQuery("#load_first").on('click', function(){
params_shop.offset_page=1; // Specify 1 since this is the first page
jQuery.getJSON(url_rest, params_shop, function(result){
resultLoopback(result); // Shows restaurants every 500 times (e.g., restaurant serial numbers, names, regions, nearest stations, etc.)
resultNum(result); // Display the total number of restaurants displayed at this time
});
});
However, I'm struggling with the following code for "To the End" because it doesn's code doesn't seem to work.
jQuery("#load_last") .on('click', function(){
jQuery.getJSON(url_rest, params_shop, function(result){
if(result.total_hit_count%500==0){
params_shop.offset_page = Math.floor(result.total_hit_count/500);
} else{
params_shop.offset_page = Math.floor(result.total_hit_count/500)+1;
}
resultLoopnext(result);
resultNum(result);
});
});
If(result.total_hit_count%500==0){
portion:
params_shop.offset_page
(current page number) if you divide the total number of hits for a restaurant by 500 (e.g., 1000, 2000 etc.) by 500 and there is no excess.
result.total_hit_count/500
(total hits divided by 500).
params_shop.offset_page
(current page number)
when the remainder comes out (usually the remainder comes out).
result.total_hit_count/500+1
(total hits divided by 500 plus 1).
If(result.total_hit_count%500==0){
part
jQuery.getJSON(url_rest, params_shop, function(result){
before processing
I thought I should, so I wrote it like that at first, but when I clicked the "To End" button, the response was completely
I didn't have any.
Therefore, jQuery.getJSON(url_rest, params_shop, function(result){
should contain
There was a response, but the restaurant's name, area, nearest station, etc. will not change just by changing the serial number of the restaurant.
I'd like to display it with the important parts updated like this, but what should I do?
The entire code of javascript was posted last time when the function of button click was left, so please refer to it.
I would appreciate it if you could reply to Mr. Unarsit, who understands the situation.
jquery
jQuery.getJSON
is only getting results on page 1.
If you want to tap the API to calculate the final page and get the page, you may want to tap the API again after touching the results.
(I think it would be easier to cache the number of pages in variables when loading for the first time.)
Example)
jQuery.getJSON(url_rest,params_shop).then(function(result){
params_shop.offset_page = Math.ceil(result.total_hit_count/500);
return jQuery.getJSON(url_rest,params_shop);
}).then(function(result){
resultLoopnext(result);
resultNum(result);
});
© 2024 OneMinuteCode. All rights reserved.