Justin Moore
Justin Moore

Reputation: 884

Unable to update Parse object with Parse JS SDK

I am testing out some basic stuff and this is confusing.

Parse JavaScript SDK v1.9.0:

<script src="parse.min.js"></script>
<script>
    Parse.initialize("KEY");
    Parse.serverURL = 'URL'
</script>

Connect to Facebook:

window.fbAsyncInit = function() {
    Parse.FacebookUtils.init({
        appId      : 'ID',
        xfbml      : true,
        version    : 'v2.7'
    });
};

(function(d, s, id){
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) {return;}
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_US/sdk.js";
    fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

Get the current user:

    var user = Parse.User.current();

All fine up to this point. I can read and display from user.

When I try to update the user:

user.set("name","test");
user.save();

RangeError: Maximum call stack size exceeded.

I checked for recursion. This is only being called one time. No idea why this error would be thrown.

EDIT: To fix syntax. Error still exists.

EDIT 2: I get the same error if I try to update the currentUser or if I set a pointer of another object to the currentUser. Example:

The following creates a new InterestObject just fine, unless I set the user column as a pointer to the currentUser. Then I get the same error.

var currentUser = Parse.User.current();
var InterestObject = Parse.Object.extend("CadetsInterest");
var intObj = new InterestObject();
intObj.save({
user: currentUser,
cadets: [checkCadets state],
cadets2: [checkCadets2 state],
cwg: [checkCWG state],
question: [txtQuestion stringValue]
}).then(function(object) {
[viewSuccess setHidden: NO];
[viewInterest setHidden: YES];
});

Upvotes: 0

Views: 156

Answers (1)

Ran Hassid
Ran Hassid

Reputation: 2788

i think the syntax in your code should be:

user.set("name","test");

and in your case you wrote:

user.set("name"),"test"

UPDATE

From the code that you provided i don't see any logIn call in order to login with facebook. I did some side project and managed to do it. What i did is the following:

  1. Go to https://developers.facebook.com
  2. Create facebook app of type Web
  3. In your facebook app URL put your server URL (in my case i did it on my localhost so i put the URL where my app is hosted)
  4. Go to your parse app and write put the following code:

<!doctype html>

<head>
  <meta charset="utf-8">

  <title>My Parse App</title>
  <meta name="description" content="My Parse App">
  <meta name="viewport" content="width=device-width">
  <link rel="stylesheet" href="css/reset.css">
  <link rel="stylesheet" href="css/styles.css">
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
  <script type="text/javascript" src="http://www.parsecdn.com/js/parse-latest.js"></script>
</head>

<body>

  <div id="main">
    <h1>You're ready to use Parse!</h1>

    <p>Read the documentation and start building your JavaScript app:</p>

    <ul>
      <li><a href="https://www.parse.com/docs/js_guide">Parse JavaScript Guide</a>
      </li>
      <li><a href="https://www.parse.com/docs/js">Parse JavaScript API Documentation</a>
      </li>
    </ul>

    <div style="display:none" class="error">
      Looks like there was a problem saving the test object. Make sure you've set your application ID and javascript key correctly in the call to <code>Parse.initialize</code> in this file.
    </div>

    <div style="display:none" class="success">
      <p>We've also just created your first object using the following code:</p>

      <code>
          var TestObject = Parse.Object.extend("TestObject");<br/>
          var testObject = new TestObject();<br/>
          testObject.save({foo: "bar"});
        </code>
    </div>
  </div>

  <script type="text/javascript">
    Parse.initialize("{PARSE_APP_ID}");
    Parse.serverURL = '{PARSE_SERVER_URL}'

    window.fbAsyncInit = function() {
      Parse.FacebookUtils.init({
        appId: '{YOUR_FB_APP_ID}',
        xfbml: true,
        version: 'v2.7'
      });
    };

    (function(d, s, id) {
      var js, fjs = d.getElementsByTagName(s)[0];
      if (d.getElementById(id)) {
        return;
      }
      js = d.createElement(s);
      js.id = id;
      js.src = "//connect.facebook.net/en_US/sdk.js";
      fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));


    setTimeout(function() {
      Parse.FacebookUtils.logIn(null, {
        success: function(user) {

          user.set("name", "test");
          user.save();

        },
        error: function(user, error) {
          alert("User cancelled the Facebook login or did not fully authorize.");
        }
      });
    }, 2000);
  </script>
</body>

</html>

In this code i do exactly the same steps that you did but then i call to Parse.FacebookUtils.logIn. I am doing it after 2 seconds just to make sure that Parse.FacebookUtils.init was executed (it's better to do inside a callback but for testing purposed i did it like that). then after i log in with my facebook account i get the user inside the success block, update his name and save it again. then in my parse-dashboard i see the following:

enter image description here

Please also make sure that your current user is logged our before doing it because maybe there is a chance that you have an active session. in order to do it simply call to

FB.User.logOut();

Upvotes: 1

Related Questions