Using parse.com and the JavaScript SDK. The code should let a user sign up and upload a profile picture.
Updated, this is the code I'm using that is returning an error when trying to sign up a user the console message is Uncaught TypeError: Cannot read property 'length' of undefined
> $('#SignUp').click(function(e) {
> UserSignUp(); });
>
>
> function UserSignUp() {
>
> var user = new Parse.User();
> userFirstname = $('#firstnamesu').val();
> userLastname = $('#lastnamesu').val();
> userUsername = $('#usernamesu').val();
> userGender = $('#gendersu').val();
> Email = $('#emailsu').val();
> PWP = $('#passwordsu').val();
>
> user.set("FirstName", userFirstname);
> user.set("LastName", userLastname);
> user.set("username", userUsername);
> user.set("gender", userGender);
> user.set("email", Email);
> user.set("password", PWP);
>
>
> var fileUploadControl = $("#pic")[0]; if (fileUploadControl.files.length > 0) { var file =
> fileUploadControl.files[0]; var name = "photo.png";
>
> var parseFile = new Parse.File(name, file);
>
> //put this inside if { parseFile.save().then(function() { //
> The file has been saved to Parse. }, function(error) { // The
> file either could not be read, or could not be saved to Parse.
> });
>
> // Be sure of ur parameters name
> // prod is extend of my class in parse from this: var prod = new products();
> user.set("ProfilePic", parseFile);
> user.save(); } ////////////Runs parse after the SignUp button has been clicked by the user////////////////////
>
> $('#SignUp').click(function(e) {
> UserSignUp(); });
>
> user.signUp(null, {
> success: function(user) {
> if (!user.existed()) {
> window.location.href = "user_home.html";
> } else {
> alert("NO WAY BUDDY");
> }
> },
> error: function(user, error) {
>
> }
> });
I was able to answer my own question by using the following code. Basically it was a case of refactoring the code into a more logical order that resolved it. The issue wasn't helped by another issue I had here which just confused matters further.Issue with parse.com user signup not working
$('#SignUp').click(function(e) {
UserSignUp();
});
function UserSignUp() {
var fileUploadControl = $("#pic")[0];
if (fileUploadControl.files.length > 0) {
var file = fileUploadControl.files[0];
var name = "photo.png";
var user = new Parse.User();
var parseFile = new Parse.File(name, file);
userFirstname = $('#firstnamesu').val();
userLastname = $('#lastnamesu').val();
userUsername = $('#usernamesu').val();
userGender = $('#gendersu').val();
Email = $('#emailsu').val();
PWP = $('#passwordsu').val();
user.set("ProfilePic", parseFile);
user.set("FirstName", userFirstname);
user.set("LastName", userLastname);
user.set("username", userUsername);
user.set("gender", userGender);
user.set("email", Email);
user.set("password", PWP);
var uri = encodeURI('http://XXXX.com/XXXX.html');
user.signUp(null, {
success: function(user) {
if (!user.existed()) {
window.location.href = uri;
}
},
error: function(user, error) {
// Show the error message somewhere and let the user try again.
}
});
};
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With