doyan doyan - 5 months ago 69
Javascript Question

Uncaught SyntaxError: Unexpected string in my javascript file

This is my likedc.js which I tried to upload but however the terminal reported me that it is failed because Error: Uncaught SyntaxError: Unexpected string in likedc.js:40 at main.js:3:1

I tried to comment but the terminal still says the same thing. I'm not sure what are the alternatives that I can amend

Parse.Cloud.define("StatusUpdate", function(request,response){
//query Installation for user
var Installationquery = Parse.Object.extend("Installation");
var query = new Parse.Query(Installationquery);
var message = request.params.message
query.equalTo("user", request.params.User);
query.find({
success: function(results) {
response.success("found user" + results)

// Do something with the returned Parse.Object values
for (var i = 0; i < results.length; i++) {
var object = results[i];
Parse.Push.send({
where: query, // Set our Installation query
data: {
alert: createMessage(message)
badge: "Increment", **//<---- Line 40**
sound: "";
}
}, {
success: function() {
// Push was successful
console.log("sent ")
},
error: function(error) {
console.log("Error " + error)
}
}
},
error: function(error) { // <--- Line 54**
alert("Error: " + error.code + " " + error.message);
}
});
})



});

var alertMessage = function createMessage(request)
{
var message = "";

if (request.object.get("StatusUpdate") === "likedby") {
if (request.user.get('postedby')) {
message = request.user.get('postedby') + ': ' + request.object.get('statusOBJID').trim();
} else {
message = "Someone liked on your status update.";
}

// Trim our message to 140 characters.
if (message.length > 140) {
message = message.substring(0, 140);
}

return message;
}
}

Kiz Kiz
Answer
    data: {
      alert: createMessage(message), //<-- add comma here
      badge: "Increment",   **//<---- Line 40**
      sound: ""  //<-- remove semicolon here
    }

For the second part, from the context I think your error block is out of place, try rearranging like

 Parse.Cloud.define("StatusUpdate", function(request, response) {
      //query Installation for user
      var Installationquery = Parse.Object.extend("Installation");
      var query = new Parse.Query(Installationquery);
      var message = request.params.message
      query.equalTo("user", request.params.User);
      query.find({
          success: function(results) {
              response.success("found user" + results)

              // Do something with the returned Parse.Object values
              for (var i = 0; i < results.length; i++) {
                  var object = results[i];
                  Parse.Push.send({
                              where: query, // Set our Installation query
                              data: {
                                  alert: createMessage(message),
                                  badge: "Increment", //<---- Line 40**
                                  sound: ""
                                }
                              }, {
                                  success: function() {
                                      // Push was successful
                                      console.log("sent ")
                                  },
                                  error: function(error) {
                                      console.log("Error " + error)
                                  }
                              });
              } 
          },
            error: function(error) { // <--- Line 54**
                alert("Error: " + error.code + " " + error.message);
            }
        });
      });