File tree 4 files changed +23
-10
lines changed
LongevityWorldCup.Website/wwwroot
4 files changed +23
-10
lines changed Original file line number Diff line number Diff line change @@ -556,13 +556,13 @@ <h2><i class="fas fa-calendar-alt"></i> Once/Year Newsletter</h2>
556
556
557
557
if ( validator . isEmail ( emailInput ) ) {
558
558
// Send POST request to the API
559
- fetch ( '/api/home/subscribe' , {
559
+ fetchWithTimeout ( '/api/home/subscribe' , {
560
560
method : 'POST' ,
561
561
headers : {
562
562
'Content-Type' : 'application/json'
563
563
} ,
564
564
body : JSON . stringify ( { email : emailInput } )
565
- } )
565
+ } , 10000 ) // 10-second timeout
566
566
. then ( response => {
567
567
if ( response . ok ) {
568
568
return response . text ( ) ; // Or response.json() if your API returns JSON
Original file line number Diff line number Diff line change @@ -890,18 +890,15 @@ <h2 data-aos="fade" data-aos-duration="700" data-aos-delay="400">1. Character Cr
890
890
applyButton . textContent = 'Submitting...' ;
891
891
892
892
// Send the data via fetch POST request
893
- fetch ( '/api/application/apply' , {
893
+ fetchWithTimeout ( '/api/application/apply' , {
894
894
method : 'POST' ,
895
895
headers : {
896
896
'Content-Type' : 'application/json'
897
897
} ,
898
898
body : JSON . stringify ( applicantData )
899
- } )
899
+ } , 10000 ) // timeout set to 10,000 ms (10 seconds )
900
900
. then ( response => {
901
- // Rest of your existing code...
902
-
903
901
if ( response . ok ) {
904
- // Handle success, perhaps redirect or show a success message
905
902
customAlert ( 'Application submitted successfully!' ) . then ( ( ) => {
906
903
localStorage . setItem ( 'contactEmail' , applicantData . accountEmail ) ;
907
904
// Clear the image variables
@@ -911,13 +908,11 @@ <h2 data-aos="fade" data-aos-duration="700" data-aos-delay="400">1. Character Cr
911
908
window . location . href = '/onboarding/application-review.html#appReviewTitle' ;
912
909
} ) ;
913
910
} else {
914
- // Handle error
915
911
customAlert ( 'Failed to submit application. Please try again later.' ) . then ( ( ) => {
916
912
applyButton . disabled = false ;
917
913
applyButton . textContent = 'Apply' ;
918
914
} ) ;
919
915
}
920
-
921
916
} )
922
917
. catch ( error => {
923
918
console . error ( 'Error submitting application:' , error ) ;
Original file line number Diff line number Diff line change @@ -433,4 +433,22 @@ <h1 data-aos="fade" data-aos-duration="700" data-aos-delay="150">2025</h1>
433
433
document . getElementById ( 'custom-alert-close' ) . addEventListener ( 'click' , function ( ) {
434
434
document . getElementById ( 'custom-alert' ) . close ( ) ;
435
435
} ) ;
436
+
437
+ function fetchWithTimeout ( url , options = { } , timeout = 10000 ) {
438
+ return new Promise ( ( resolve , reject ) => {
439
+ const timer = setTimeout ( ( ) => {
440
+ reject ( new Error ( 'Request timed out' ) ) ;
441
+ } , timeout ) ;
442
+
443
+ fetch ( url , options )
444
+ . then ( response => {
445
+ clearTimeout ( timer ) ;
446
+ resolve ( response ) ;
447
+ } )
448
+ . catch ( err => {
449
+ clearTimeout ( timer ) ;
450
+ reject ( err ) ;
451
+ } ) ;
452
+ } ) ;
453
+ }
436
454
</ script >
Original file line number Diff line number Diff line change @@ -2358,7 +2358,7 @@ <h3>Proofs</h3>
2358
2358
}
2359
2359
2360
2360
function fetchFullAthleteData ( athleteNameText , athleteData ) {
2361
- fetch ( '/api/data/athletes' )
2361
+ fetchWithTimeout ( '/api/data/athletes' , { } , 10000 ) // 10-second timeout
2362
2362
. then ( response => response . json ( ) )
2363
2363
. then ( athletes => {
2364
2364
const fullAthleteData = athletes . find ( a => a . Name === athleteNameText ) ;
You can’t perform that action at this time.
0 commit comments