If your server is not returning JSON, try removing:
dataType: 'json'
Otherwise you may be ending up with a fail event, which is easy to test for:
fail: function(e, data) { alert('Fail!'); }
https://github.com/blueimp/jQuery-File-Upload/wiki/Options#datatype
AJAX Options
The jQuery File Upload plugin makes use of jQuery.ajax() for the file upload requests. This is true even for browsers without support for XHR, thanks to the Iframe Transport plugin.
The options set for the File Upload plugin are passed to jQuery.ajax() and allow to define any ajax settings or callbacks.
The ajax options processData
, contentType
and cache
are set to false
for the file uploads to work and should not be changed.
The timeout
setting is set to 0
. See pull request #3399 for the reasoning behind this.
The following options are also set by the plugin, but can be useful to customize:
url
A string containing the URL to which the request is sent.
If undefined or empty, it is set to the action property of the file upload form if available, or else the URL of the current page.
- Type: string
- Example:
'/path/to/upload/handler.json'
type
The HTTP request method for the file uploads. Can be "POST", "PUT" or "PATCH" and defaults to "POST".
- Type: string
- Example:
'PUT'
Note:
"PUT" and "PATCH" are only supported by browser supporting XHR file
uploads, as iframe transport uploads rely on standard HTML forms which
only support "POST" file uploads. See Browser support.
If the type is defined as "PUT" or "PATCH", the iframe transport will
send the files via "POST" and transfer the original method as "_method"
URL parameter.
Note: As was noted above, it's a common practice to use "_method" to transfer the type of your request. For example, "Ruby on Rails" framework uses a hidden input with the name "_method" within each form, so it will likely override the value that you will set here.
dataType
The type of data that is expected back from the server.
Note: The UI version of the File Upload plugin sets this option to "json" by default.
- Type: string
- Example:
'json'
done
Callback for successful upload requests. This callback is the equivalent to the success callback provided by jQuery ajax() and will also be called if the server returns a JSON response with an error property.
- Example:
function (e, data) {
// data.result
// data.textStatus;
// data.jqXHR;
}