Getting a strange unexpected token with creating a file upload in React.js
I am using React as framework to create input for a project. Input is a name, photo and an optional comment. The name and comment I got working, but the photo (being a file) gives me some trouble.
I am using this as a method for uploading. (I know that the quality of the photo must be very low to use base64 for it, but that is not a problem for this project.)
However, when I used this code, my browser threw an Unexpected token error in the console, at a location where there was just a tab. I have located the error to this piece of code (by commenting out different pieces).
reader.onload = function(output){
fileUpload.set({
file: output.target.result
});
$.when(fileUpload.save())
.done(function(){
this.setState({
uploaded: true
});
}.bind(this));
}.bind(this));
I just can't see what is wrong with it and why it is throwing that error.
Answer
It looks like your parens may be mismatched. Here's the same code with additional formatting:
reader.onload = function(output) {
fileUpload.set({ file: output.target.result });
$.when(fileUpload.save())
.done(
function() {
this.setState({ uploaded: true });
}.bind(this)
);
}.bind(this)
); // extra
The last line has an additional )
that does not have a matching (
at the start of the expression.
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM