0

I wrote a upload script using dojo and form:

HTML

<form action="/Form/Upload" enctype="multipart/form-data" id="FormId" method="post">                
<input id="..." name="..." type="file" onchange="UploadImage(this, FormId);" />
</form>

Dojo

require([
    "dojo/dom-attr",
    "dojo/request/iframe"],
function (domattr, iframe) {
    UploadFile = function (Uploader, form) {
        if (Uploader.value != "") {
            if (Uploader.files[0].size < 50000000) {
                iframe(form.formAction, {
                    form: form,
                    handleAs: "text",
                    timeout: 20000,
                    method: "POST"
                }).then(function (name) {
                    .
                    .
                    .
                }, function (err) {
                    .
                    .
                    .
                });
            }
        }
    };
};

For some reason I get an error

Uncaught SyntaxError: Unexpected token ILLEGAL

But this does not happen every time! After I refresh the page it sometimes works and some times gives an error. Then I run debugger in chrome it doesn't even get to dojo. It throws an error on the <form> row. (all the dots is a irrelevant code because it doesn't get to that point when the error is thrown but is works perfectly after I refresh the page)

levkaster
  • 2,670
  • 2
  • 25
  • 32
  • Remove your 3 dots after then() and function() ? – trainoasis Jan 16 '15 at 08:16
  • all the dots is a irrelevant code because it doesn't get to that point when the error is thrown but is works perfectly after I refresh the page – levkaster Jan 16 '15 at 08:26
  • 1
    If there is a syntax error, it would be when the browser is parsing *all* of the code before *any* of it runs, so I wouldn't rule out any code as irrelevant. Also, since you're saying it snags on the `
    ` line, maybe seeing the whole page source in context would be better.
    – Ken Franqueiro Jan 16 '15 at 13:44

1 Answers1

1

You are missing one ) at the end (for 'require')

});

Does this work? ofcourse without dots in this part:

}).then(function (name) {
                .
                .
                .
            }, function (err) {
                .
                .
                .

Also make sure there are no invisible weird chars in your text. They can be inserted by some apps (Aptana did this for me for instance).

Check this question/answer also.

Community
  • 1
  • 1
trainoasis
  • 6,419
  • 12
  • 51
  • 82