JSON error when using drop zone

Bug #1216764 reported by Kristina Hoeppner
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mahara
Fix Released
High
Robert Lyon

Bug Description

latest Mahara 1.8.0dev

When adding a file via drag and drop to a journal entry, I get "SyntaxError: JSON.parse: unexpected character".

Revision history for this message
Robert Lyon (robertl-9) wrote :

Hi Kristina,

This error happens when the returning code is the html page rather than the expected json data. The html page is not expected to be returned so obviously either a field is missing from being passed at the dropping of files (or conversly a field that is not needed is eing passed, eg a cancel button field). I have encountered this a couple of times and had added fixes for it for a bunch of scenarios.

But you've discovered another one.

Are you able to let me know which page and what things were enabled on the page eg license meta data, auto resizing etc and what browser you were using? I suspect there is a special combo of things happening that is causing the wrong expected results being passed back to the page.

Cheers

Bob

Robert Lyon (robertl-9)
Changed in mahara:
status: Triaged → In Progress
Revision history for this message
Aaron Wells (u-aaronw) wrote :

Does it send the HTML page whenever there's an error/warning on the page before it gets to the part where it would send JSON?

Revision history for this message
Robert Lyon (robertl-9) wrote :

Not quite, the problem is there are certain form fields (which can vary depending where the fileuploader is included) that are used to cancel the file upload process. So when dropzone slurps up all the form field from it's enveloping form it gets fields like '[whatever]_cancel' that it doesn't want.

In the php code there are things like if('cancel') are higher up in the hierarchy of things to do and when a cancel is encountered the normal response from pieforms is to return the page to replace itself, which is all HTML. So not an error, just normal way of things.

However when the point of actually trying to upload a file is reached the response back is in JSON (either success or fail), which is what dropzone is expecting, and not the HTML one.

if it gets the HTML response it throws the 'SyntaxError: JSON.parse: unexpected character' - that tells me that it is receiving a field (like cancel) that it shouldn't.

These should all be ironed out now. But if the error occurs again the first thing is to do a console.log() on the form fields that filedropzone.js is sending and see if any of those are not meant to be sent on a fileupload submit.

Revision history for this message
Mahara Bot (dev-mahara) wrote : A change has been merged

Reviewed: https://reviews.mahara.org/2427
Committed: http://gitorious.org/mahara/mahara/commit/c008814e892741877ca9540b66b5d12ac75f1741
Submitter: Robert Lyon (<email address hidden>)
Branch: master

commit c008814e892741877ca9540b66b5d12ac75f1741
Author: Robert Lyon <email address hidden>
Date: Thu Aug 22 09:41:10 2013 +1200

Fixed up dropzone to be more generic (Bug #1216764)

- allow it to work in fileupload forms with id other than 'files'
- got it to work with resumes file upload forms where they pass a
field called 'cancel_submitform'.
- got it to work with journal upload form

Change-Id: I62b1f6045b1dff9070ec7dbbacae488ee4eea5a5
Signed-off-by: Robert Lyon <email address hidden>

Robert Lyon (robertl-9)
Changed in mahara:
status: In Progress → Fix Committed
Aaron Wells (u-aaronw)
Changed in mahara:
milestone: 1.8rc1 → 1.8.0
Aaron Wells (u-aaronw)
Changed in mahara:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.