简体   繁体   中英

I am getting an error: TypeError: e.changes is undefined while updating the user object using Parse API. How to resolve this?

Below is the code:

<!DOCTYPE html>  
  <html>
   <head>
    <title>Update Your Details</title>
    <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
    <script type="text/javascript" src="http://www.parsecdn.com/js/parse-1.1.14.min.js"></script>
   </head>

<body>
    <table>
        <tr><td>Username:</td><td><input type="text" name="name" id="name" /></tr>
        <tr><td>Work:</td><td><input type="text" name="work" id="work" /></td></tr>
        <tr><td>Education:</td><td><input type="text" name="edu" id="education" /></tr>
        <tr><td>Password:</td><td><input type="password" name="password" id="password" /></td></tr>
    </table>
    <br />
    <button id="save">Done</button>

    <script type="text/javascript">   

            $(document).ready(function() {
                $('#save').click(function(e) {
                //  e.preventDefault();
                    console.log("before2 clicked!");
                    Parse.initialize("XXXX","XXXX");
                    console.log("before clicked!");

                    var profileSave = Parse.User.current();

                    var userName = document.getElementById('name').value;
                    var password = document.getElementById('password').value;
                    var work = document.getElementById('work').value;
                    var education = document.getElementById('education').value;
                    alert("userName = " + userName + "password = " + password + " work = " + work + " education " + education);
                    profileSave.setUsername("username", userName);
                    profileSave.setPassword("password", password);
                    profileSave.set("work", work);
                    profileSave.set("education", education);

                    profileSave.save(null, {
                        success: function(profileSave) {
                            profileSave.save();
                        },
                        error: function(profileSave, error) {
                            // Fail

                        }
                    });

                    alert("All the updates are being saved!");
                    window.open("welcome.html", '_self');
                });

            });
    </script>   

</body>

 </html>

I have searched on google and stackoverflow and the internet, but can't find the solution to my problem. In this code basically i want to update the details of the User Object which is currently logged in. But while updating it shows error specified above.

Why are you calling profileSave.save(); a second time in the success block? I believe this is the one causing the problem as there are no further changes at that time.

You can safely remove the extra save() call from the success block and everything should be fine.

Currently your code says "save these changes, and if it works, try and save a 2nd time with no additional changes".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM