Another way to figure this out is to attempt to run the code in your web browser.
Mine tells me in the browser console: Uncaught SyntaxError: Unexpected token '.'
at the fullstop just before the bind:
return false;
}.bind(this),
Syntax highlighting in my editor shows me when I select the closing brace just before the fullstop, that the matching opening brace is from the else statement. That’s not right, for it should be the start of a function instead. That means that the end of the if statement is missing. But where should that closing brace for the if statement go? It doesn’t make sense to enclose both the return and the confirm.
if (response.success)
{
new jBox('Notice', {
color: 'red',
content: 'Please fill in your name and email'
});
} else {
new jBox('Notice', {
color: 'green',
content: 'You filled in the textfields'
});
myConfirm.close();
return false;
}
So moving the return out of the if statement makes sense:
if (response.success)
{
new jBox('Notice', {
color: 'red',
content: 'Please fill in your name and email'
});
} else {
new jBox('Notice', {
color: 'green',
content: 'You filled in the textfields'
});
myConfirm.close();
}
return false;
But does it make sense for myConfirm to be in the if statement? Someone else other than me would know more about that, so I’ll leave it inside the for loop for now.
What happens when I now try to run that code in my web browser? I’m told: Uncaught SyntaxError: Unexpected token ')'
at the open method.
cancel: function() {
//disable(),
window.location.href = "/index.html";
}).open();
In my code editor when I select the closing parentheses just before the open method, it is the opening brace for the ajax object that’s shown as the opening of it. It’s not valid for a brace to open and a parenthesis to close. { … ), so something’s missing. Let’s put in the closing brace for the cancel function:
cancel: function() {
//disable(),
window.location.href = "/index.html";
}
}).open();
And my web browser give me another error at a new location. New is good. This time the error is Uncaught SyntaxError: Unexpected token ')'
at a different line. It’s at a strange piece on the line below the open method.
}).open();
)};
It seems obvious that the brace and parenthesis are switched around, but it does no harm to check. Placing my cursor on the closing parenthesis I see that the opening part of it is the brace at the start of the confirm function. I now feel more confident about switching around the parenthesis and brace from )};
to });
and check again. The closing parenthesis doesn’t have a matching opening parenthesis. Instead the opening is a curly brace from the new jBox confirm line.
The solution is to use a single closing brace for to close the confirm method, and follow it with }); to close the new jBox confirm.
}).open();
}
)};
The deep nesting that you have in your code there does make it more difficult for you to understand what your code is supposed to be doing.
Back to the web browser and I’m told Uncaught ReferenceError: jBox is not defined
which spells the end of my troubleshooting. The code structure looks to be valid now, and you can carry on with testing things out in an environment that supports what the code is supposed to do.