Parse & Javascript: Insert a record

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

Say you are an independent filmmaker and you want to keep track of the movies you have made.  Let’s make an App to do that.

<!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.set('titleName', 'Dallas Buyers Club' );
    movieObject.set('actorName', 'Matthew McConaughey');
    movieObject.set('releaseYear', 2013);

    movieObject.save(null, {
        success: function (object) {
            $('.success').show();
        },
        error: function (model, error) {
            $('.error').show();
        }
    })

</script>

</body>
</html>
Try The Code

Once you have ran the above script, you can check in the Data Browser in Parse if the record is correctly inserted.

parse_record1

We take note of the 2 lines below.

Below here the simple syntax to create a new subclass of Parse.Object.

var MovieObject = Parse.Object.extend("MovieObject");

Here, we create a new instance of that class.

var movieObject = new MovieObject();
Series Navigation<< Parse & JS: Parse.Object
Parse & JS: Insert a record using save method >>

Leave a comment

Leave a Reply