Parse & JS: Insert a record using save method

This entry is part 9 of 25 in the series Parse & Javascript

If you prefer, you can set attributes directly in your call to save instead to save a record.

<!doctype html>
<head>
    <title>My Parse App</title>
    <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-1.2.17.min.js'></script>
</head>

<body>

<div>
    <div style='display:none' class='error'>
        <h1>Failed to connect to Parse database</h1>
    </div>

    <div style='display:none' class='success'>
        <h1>Successfully inserted a movie record</h1>
    </div>
</div>

<script>
    Parse.initialize('5d3sro43zBGj8AMYqWND5bFYMzAan7f5P5euZm7M', 'hlRZZqAylA7Fmah4Kk6ma8WK7QCT4cHrxjafnnkI');
    var MovieObject = Parse.Object.extend('MovieObject');
    var movieObject = new MovieObject();

    movieObject.save({
        titleName: 'Dallas Buyers Club',
        actorName: 'Matthew McConaughey',
        releaseYear: 2013
    }, {
        success: function (movieObject) {
            $('.success').show();
        },
        error: function (movieObject, error) {
            $('.error').show();
        }
    })

</script>

</body>
</html>
Try The Code

For Parse, on each save, it will create a unique objectId for each record.

parse_record2

Series Navigation<< Parse & Javascript: Insert a record
Parse & JS: Retrieving object using objectid >>

Leave a comment

Leave a Reply