I cannot find this syntax error [closed] - javascript

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm going to feel like a complete idiot once this is pointed out to me, but I've got a syntax error I cannot figure out where the issue is coming from. Here is my code (error appears on last line but I doubt its that line that caused that):
// handle GCM notifications for Android
function onNotificationGCM(e) {
switch( e.event )
{
case 'registered':
if ( e.regid.length > 0 )
{
// Your GCM push server needs to know the regID before it can push to this device
// here is where you might want to send it the regID for later use.
PushWoosh.appCode = "33F93-5013B";
PushWoosh.register(e.regid, function(data) {
alert("PushWoosh register success: " + JSON.stringify(data));
}, function(errorregistration) {
alert("Couldn't register with PushWoosh" + errorregistration);
});
}
break;
Thanks guys, I'm feeling like an idiot here and had a frustrating day.

Your onNotificationGCM() function is not closed, and neither is the switch block contained within it. The JavaScript parser is expecting to see two additional close braces (}) but the input file terminates before they are seen.
My guess is that you need to add these two braces after your break; statement, prior to the assignment of PushNotification.prototype.register.

Related

JSON.parse error: invalid character at position 1 [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
For some reason I'm getting a parse error when trying to send a post request to the server
$.post("../php/user_handler.php", formData, function(data) {
var result = JSON.parse(data);
if(result.status === 'error') {
$('#' + result.control + '-error').html(result.message).css('display', 'inline-block');
} else {
$('#form-message').html(result.message).css('display', 'inline-block');
}
});
The message I'm getting implies that the error is with the syntax of the first character of the first line, but I really don't understand how; I've checked it against several examples of how to make this request and it looks just fine to me.
Simply means that your string is not JSON. First character has to be "{" or "[" but it is not. Might be empty or start with something else. Dump the thing aout on the console.log before you try to parse it.Might help ;)

Best approach to Logging in javascript [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to console.log but then turn it off in production without deleting the logs statements.
What are other logging levels and how can i utilise them?
What benefits do logging libraries such as log4js offer?
Place this code in your webpage
if(window.location.hostname=="example.com"){
console.log = function(){
return;
}
}
What it will do is, if the domain name is example.com it will override the console.log functionality and it will print nothing in console.
This way it will also work in your local environment.
var myAPI={isLogged:false};
(function(api){
if(window.location.hostname=="dev.example.com"){
myAPI.isLogged=true;
}
api.log=function(msg,level){
if(!level){level='log'} //can be : warn, info, error, debug or log
if( myAPI.isLogged){
console[level](msg);
}
};
})(myAPI) ;
Then , use :
myAPI.log(new Date()+' This is security check ');
or
myAPI.log(new Date()+' Wrong password ','error');

Why is my delete where statement not working? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am trying to delete a user from table USERS. Unfortunately, I keep getting sent to onSqlError. I can't figure out why. When I alert the request it gives me the correct name for the getTheId variable. Not too familiar with sql so maybe I have written something incorrectly. Any pointers appreciated.
// DELETE RECORD
function deleteRecord(getTheId){
deleteUser.onclick = (function () {//deleteUser is an element generated for each user when a button is clicked
var sqlStr2 = 'DELETE FROM USERS WHERE username = '+getTheId+'';
alert("SQL: " + sqlStr2); //This gives me the statement above with the correct name of the user clicked.
if (db){
console.log("db is there");//this logs
db.transaction(function(tx) {
tx.executeSql(sqlStr2);
}, onSqlError, onSqlSuccess); //THEN I GET SENT TO ERROR
}
});
}
Try this:
var sqlStr2 = "DELETE FROM USERS WHERE username = '"+getTheId+"'";
Try adding a ';' to the end of your statement, although without an error message it's hard to tell.

False or null for error checking -Javascript [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I was wondering which of the two is appropriate:
error = null or error = false
if(error) {
//handle it
}
Is it a matter of preference/coding style or does one have an actual advantage over the other. Is it contextual? Is there a consensus at all on the issue?
Thank you.
Both the examples you have given will evaluate to false.
In this simplistic example you have given there is no difference - both null and false will trigger the conditional expression.
Let me try again.
error = null;
if (!error === true) {
// this will work
};
if (error === false) {
// this will not work
};
Here is a fiddle you can test in.
Both statements evaluate to false.
var error = false; will be appropriate if you only want to know about error or not. If some cases, you may want to have error message in the error, then you can assign to null.
Both are valid. The choice is based on purpose of error variable.
I'd rather use the error variable as a string, then you can add messages to help debugging, telling the developer where the problem occured.

how to deobfuscate javascript [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
can any one tell me how to de-obfuscate this?
É=-~-~[],ó=-~É,Ë=É<<É,þ=Ë+~[];Ì=(ó-ó)[Û=(''+{})[É+ó]+(''+{})[ó-É]+([].ó+'')[ó-É]+(!!''+'')[ó]+({}+'')[ó+ó]+(!''+'')[ó-É]+(!''+'')[É]+(''+{})[É+ó]+({}+'')[ó+ó]+(''+{})[ó-É]+(!''+'')[ó-É]][Û];Ì(Ì((!''+'')[ó-É]+(!''+'')[ó]+(!''+'')[ó-ó]+(!''+'')[É]+((!''+''))[ó-É]+([].$+'')[ó-É]+'\''+''+'\\'+(... Masked for confidentiality reasons
Look for the "()" in the end. Those are for executing the obscured function code. If you remove the last one and use "toString()" instead in node you will get the following (After formatting a bit):
function anonymous() {
na = prompt('Entrez le mot de passe');
if(a == 'I changed this to not make it too easy for you' {
alert('bravo');
} else {
alert('fail...');
}
}
Try it yourself, but always be careful, since if you are not careful this kind of code can run harmful stuff on your computer.
PS: A few more words about how it actually works. Those weird french seeming letters everywhere are just variables, which are defined in the beginning. É for example has the value of 2, since using the bitwise not operator on an empty array results a -1, and -~-(-1) = 2. All those backslashes are then used in combination with this numeric variables to get characters which eventually form the code of the function.

Categories

Resources