Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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);
                    }
                });
            });
        });
share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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

share|improve this answer
    
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? –  Dano007 yesterday
    
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); ? –  Dano007 yesterday
    
contact.set("BadgeName", badgeselected); (although I don't know what badgeselected is, but probably a string...?) –  Handsomeguy 23 hours ago
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.