未捕获的SyntaxError:我的javascript文件中的意外字符串

时间:2016-06-12 06:22:09

标签: javascript parse-platform notifications cloud-code

这是我尝试上传的我的likesc.js,但是终端报告我失败了,因为错误:未捕获的SyntaxError:在likes.Js中的意外字符串:40在main.js:3:1 < /强>

我试着发表评论,但终端仍然说同样的话。我不确定我可以修改哪些替代方案

        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;
              }
    }

1 个答案:

答案 0 :(得分:1)

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

对于第二部分,从上下文我认为你的错误块不合适,尝试重新排列,如

 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);
            }
        });
      });