Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery file upload throws an error

I have an ASP.NET MVC app. This app requires jQuery 2.1 due to other jquery plugins in the app. I am trying to provide a way for my user's to upload pictures. In an attempt to do that, I was looking at the jQuery file uploader. My JavaScript looks like this:

$('#userPicture').fileupload({
  dataType: 'json',
  done: function (e, data) {
  }
});

The userPicture markup looks like this:

<input id="userPicture" type="file" name="userPicture" data-url="/pictures/User/@ViewBag.UserId">

The page initially loads without any errors. When I choose a picture though, I get an error that says:

Uncaught Error: no such method 'process' for fileupload widget instance       jquery-2.1.1.js:250

No image preview is shown. How can I choose a picture and show a client-side preview via a JQuery plugin that works in IE 8+

like image 888
JQuery Mobile Avatar asked Sep 29 '14 19:09

JQuery Mobile


People also ask

Is it possible to upload files using jQuery and Ajax?

I made a complete javascript function using jquery and ajax to upload files ... Everything is working perfectly untill I realized that for some files the error function is fired in ajax instead of success function.

Why do I get an empty file upload result?

For anyone getting the "Empty file upload result" error when uploading images, make sure that you have the gd-extension for php installed. Sorry, something went wrong. great one... Sorry, something went wrong. I'm sorry, but what do you mean by the reply wasn't an array?

How to activate the submit button when uploading a file?

If the user tries to upload a file of more than 300kb, the submit button will be disabled. And if the file uploads less than 300kb then the submit button will be activated. so first create a simple form using plain HTML.

How do I increase the size of the files uploaded?

You must to change the upload_max_filesize, post_max_size, max_execution_time and max_input_time in php.ini settings to fit your need. Changing these settings correctly will allow you to increase or decrease the size of the files uploaded and avoid the ""Empty file upload result".


2 Answers

I had the same issue with Chrome, in my case the problem seem to be is missing jquery plugin "jquery.fileupload-process.js" as @jevgenig mentioned in his comments. hope this could help someone

like image 69
Tharindu Avatar answered Oct 12 '22 02:10

Tharindu


From the specs I checked, jQuery 2.x supports IE9+.

Source: http://jquery.com/browser-support/

So jQuery 2.1 doesn't support IE8.

If you're using the jQuery plugin you mentioned, there's very few support for IE9-:

  • You can only upload one file at a time.
  • You can only upload using the normal "File Input".
  • There's no image preview.
  • There's no upload progress bar.
  • etc.

If you're supporting modern browsers (Firefox, Chrome, IE10+):

  • You can drag-and-drop files.
  • You can upload multiple files.
  • You can preview images.
  • You can see the upload progress.
  • etc.

Here's the full list:

https://github.com/blueimp/jQuery-File-Upload/wiki/Browser-support

You're problem is most probably related to the jQuery 2.1 support for IE8.

Possible solutions:

1- use an older jQuery version. You can use any jQuery 1.6+ with the jQuery File Upload plugin (Source: https://github.com/blueimp/jQuery-File-Upload). jQuery 1.x has support for IE6+, so it supports IE8.

2- (RECOMMENDED) get rid of IE8. Upgrade your jQuery version to the latest stable version. Use the latest version of the jQuery File Upload plugin. Provide a simple HTML upload for the IE8 users.

like image 45
Wissam El-Kik Avatar answered Oct 12 '22 00:10

Wissam El-Kik