Click here to Skip to main content
15,890,438 members
Home / Discussions / JavaScript
   

JavaScript

 
GeneralRe: trying to calculate a retirement date by adding 66 years on to a Date of birth value Pin
Barnsley72-Feb-17 0:05
Barnsley72-Feb-17 0:05 
Questionsubmit button Enable Disable Function Using Javascript and Ajax with Html and CSS Pin
Member 1297691031-Jan-17 20:17
Member 1297691031-Jan-17 20:17 
QuestionRe: submit button Enable Disable Function Using Javascript and Ajax with Html and CSS Pin
ZurdoDev1-Feb-17 1:57
professionalZurdoDev1-Feb-17 1:57 
Questionangular translate problem Pin
Member 1103130431-Jan-17 20:13
Member 1103130431-Jan-17 20:13 
AnswerRe: angular translate problem Pin
Nathan Minier1-Feb-17 1:24
professionalNathan Minier1-Feb-17 1:24 
GeneralRe: angular translate problem Pin
Member 110313041-Feb-17 2:08
Member 110313041-Feb-17 2:08 
AnswerRe: angular translate problem Pin
Nathan Minier1-Feb-17 2:17
professionalNathan Minier1-Feb-17 2:17 
QuestionAJAX javascript Query Not executing properly Pin
Jason Nielsen24-Jan-17 14:18
Jason Nielsen24-Jan-17 14:18 
JavaScript

I am hoping to find some assistance with a script I am trying to build for our gym. I am rookie javascript programmer and have hit a rut. I will try to keep short and descriptive.

I am using an apikey from Wodify(system for our gym) and a ajax javascript query in our squarespace website to pull the workout down. So Wodify has workout, I want script in squarespace to grab it and display it. (I have this working).

The issue I am running into is I want the script to look to and see if current time is 7PM or greater. If it is 7PM or greater I want the script to grab tomorrow's dates workout (so 25th today). If the time is less than 7PM then it keeps todays workout. Final piece of logic is, if it is after 7PM but there is not a workout posted, then keep today's workout. What I have works some of the time, but other times during the day is incorrect. For some reason it appears the correct date is being applied in the function. I have attached the code below.

I apologize if this is a wall of garbage Smile | :) I really am terrible with javascript.

JavaScript



function loadFormattedWOD(selector, apiKey, date, location, program) {
$.ajax({
url: 'https://app.wodify.com/API/WODs_v1.aspx',
data: {
apiKey: apiKey,
date: date,
location: location,
program: program,
type: "json"
},
dataType: "json",
success: function(data){
try {
if(data && data.RecordList.APIWod.FormattedWOD) {
$(selector).html(data.RecordList.APIWod.FormattedWOD);
return "worked";

}
} catch(err) {
return null;
}
}
});
}
function loadFormattedWOD(selector, apiKey, date, location, program, callback) {
$.ajax({
url: 'https://app.wodify.com/API/WODs_v1.aspx',
data: {
apiKey: apiKey,
date: date,
location: location,
program: program,
callback: callback,
type: "json"
},
dataType: "json",
success: function(data){
try {
if (data && data.RecordList.APIWod.FormattedWOD) {
$(selector).html(data.RecordList.APIWod.FormattedWOD);
console.log('worked');
}
} catch(err) {
if (callback) callback();
}
}
});
}
today = new Date()
if (today.getHours() >=19) {today.setDate(today.getDate()+1);}
else {today.setDate(today.getDate()+0);}
var dateString = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
if(loadFormattedWOD("#wodbody", "myapikey", dateString, "MYGYM", "CrossFit") == null) {
retryWithToday();
}
function retryWithToday() {
today.setDate(today.getDate() - 1);
var dateString = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
loadFormattedWOD("#wodbody", "myapikey", dateString, "MYGYM", "CrossFit");
}
loadFormattedWOD("#wodbody", "myapikey", dateString, "MYGYM", "CrossFit");


Thank You
Jason

AnswerRe: AJAX javascript Query Not executing properly Pin
F-ES Sitecore24-Jan-17 23:04
professionalF-ES Sitecore24-Jan-17 23:04 
PraiseRe: AJAX javascript Query Not executing properly Pin
Jason Nielsen25-Jan-17 6:45
Jason Nielsen25-Jan-17 6:45 
AnswerRe: AJAX javascript Query Not executing properly Pin
F-ES Sitecore25-Jan-17 3:48
professionalF-ES Sitecore25-Jan-17 3:48 
GeneralRe: AJAX javascript Query Not executing properly Pin
Jason Nielsen28-Jan-17 17:06
Jason Nielsen28-Jan-17 17:06 
GeneralRe: AJAX javascript Query Not executing properly Pin
F-ES Sitecore29-Jan-17 22:00
professionalF-ES Sitecore29-Jan-17 22:00 
GeneralRe: AJAX javascript Query Not executing properly Pin
F-ES Sitecore30-Jan-17 23:01
professionalF-ES Sitecore30-Jan-17 23:01 
Questiondwg to jpg using javascript Pin
solynaseng19-Jan-17 4:50
solynaseng19-Jan-17 4:50 
AnswerRe: dwg to jpg using javascript Pin
Eddy Vluggen19-Jan-17 4:56
professionalEddy Vluggen19-Jan-17 4:56 
GeneralRe: dwg to jpg using javascript Pin
solynaseng19-Jan-17 5:32
solynaseng19-Jan-17 5:32 
AnswerRe: dwg to jpg using javascript Pin
Richard MacCutchan19-Jan-17 5:29
mveRichard MacCutchan19-Jan-17 5:29 
GeneralRe: dwg to jpg using javascript Pin
solynaseng19-Jan-17 5:34
solynaseng19-Jan-17 5:34 
GeneralRe: dwg to jpg using javascript Pin
Richard MacCutchan19-Jan-17 5:42
mveRichard MacCutchan19-Jan-17 5:42 
GeneralRe: dwg to jpg using javascript Pin
solynaseng19-Jan-17 6:00
solynaseng19-Jan-17 6:00 
GeneralRe: dwg to jpg using javascript Pin
dandy7219-Jan-17 6:40
dandy7219-Jan-17 6:40 
GeneralRe: dwg to jpg using javascript Pin
Rajesh R Subramanian19-Jan-17 12:38
professionalRajesh R Subramanian19-Jan-17 12:38 
GeneralRe: dwg to jpg using javascript Pin
dandy7219-Jan-17 13:42
dandy7219-Jan-17 13:42 
GeneralRe: dwg to jpg using javascript Pin
Richard MacCutchan19-Jan-17 22:26
mveRichard MacCutchan19-Jan-17 22:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.