3

I have to upload an image onto the ColdFusion server. I have used FormData for the AJAX request to pass image file. It works fine for FF and chrome but gives issues in IE and the form does not get posted. Is there any alternative way to do so? So that it works fine for FF, Chrome, IE8+.

var formData = new FormData($(obj)[0]);
var actionPage = $(obj).attr('action');
if (validForm) {
    $('.mainPage').html('<div style="padding-top:20px;" align="center"><img alt="loading" src="/rpnet/images/ajax-loader.gif" /></div>');
    $.ajax({
        url: actionPage,
        type: 'POST',
        data: formData,
        async: false,
        cache: false,
        contentType: false,
        processData: false,
        success: function (returndata) {
          $('.mainPage').html(returndata);
        }
    });
}
return false;

This is the code I have used for posting the form.

Mitali
  • 111
  • 3
  • 11
  • Try setting the “Cache-Control” header with a value of “no-cache,no-store” on your server. – Aravind Jun 29 '15 at 13:17
  • can you give some more details what you mean by "issues". – M.Scherzer Jun 30 '15 at 07:20
  • @Aravind Have done that, no solution. – Mitali Jul 01 '15 at 05:49
  • @M.Scherzer The form posted is found empty in IE but works fine in other browsers – Mitali Jul 01 '15 at 05:50
  • 2
    From memory older versions of IE don't support uploading files through AJAX a workaround used to be using a iFrames. Save yourself some pain and use a jquery plugin that falls back gracefully to iframes for older browsers like IE. e.g. http://malsup.com/jquery/form/#code-samples A similar question is asked here: http://stackoverflow.com/questions/166221/how-can-i-upload-files-asynchronously – M.Scherzer Jul 02 '15 at 03:05
  • Either you can use jquery plugin as mentioned by @M.Scherzer Or you can use IFrame based solution : https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Sending_forms_through_JavaScript – sudip Feb 08 '18 at 10:45

0 Answers0