0

I would have expected the following parse.com/javascript code block to save the selected "badeselected" variable to the parse class "myBadges" and automatically create a relationship back to the "_USer" class.

There are no errors being returned in the console log, however neither are there any records being added to the "myBadges" class.

I'm not sure what error I've made here?

    Parse.initialize("XXXXX", "XXXXX");

var badgeselected = $("#go").attr("src") 
var contact = Parse.Object.extend("myBadges");
var contact = Parse.User.current();

$(document).ready(function () {
            $("#send").click(function () {
               contact.set("BadgeName", badgeselected);
                     console.log("done");

                contact.save(null, {
                    success: function (results) {
                        // The object was saved successfully.
                        location.reload();
                    },
                    error: function (contact, error) {
                        // The save failed.
                        // error is a Parse.Error with an error code and description.
                        alert("Error: " + error.code + " " + error.message);
                    }
                });
            });
        });

1 Answer 1

1

You are declaring contact twice. First as an extension called myBadges, and then as current user (discarding the first). Check the current user object in the data browser. You should find the badges there.

UPDATE

Here is an example from the javascript guide:

var GameScore = Parse.Object.extend("GameScore");
var gameScore = new GameScore();

gameScore.set("score", 1337);
gameScore.set("playerName", "Sean Plott");
gameScore.set("cheatMode", false);

gameScore.save(null, {
  success: function(gameScore) {
    // Execute any logic that should take place after the object is saved.
    alert('New object created with objectId: ' + gameScore.id);
  },
  error: function(gameScore, error) {
    // Execute any logic that should take place if the save fails.
    // error is a Parse.Error with an error code and description.
    alert('Failed to create new object, with error code: ' + error.description);
  }
});

You should be able to use this in your jquery code. See how they first declare GameScore as an extension, and then gameScore as new GameScore(); And THEN they set the values on the object.

More info: https://parse.com/docs/js_guide

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you, If I remove the current user variable I get the following error Uncaught TypeError: Object function (){e.apply(this,arguments)} has no method 'set' How can I address that?
many thanks. I'd seen that code on the parse.com site, what I was unsure about was how to parse in my variable to the object and not a fixed value such as "Sean Plot" if that makes sense? Would it be along the lines of contact.set("BadgeName", "Sean Plott", badgeselected); ?
contact.set("BadgeName", badgeselected); (although I don't know what badgeselected is, but probably a string...?)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.