File upload using ajax is not working in Safari Mac but it working in other browsers like chrome, FF, IE

File upload using ajax is not working in Safari Mac but it working in other browsers like chrome, FF, IE

When we remove processdata and formdata variable from ajax options everything is working fine except file upload.

Please help me urgently, this is blocker issue for me.

Thanks in advance

Sample code:

params = new FormData();
params.append(“message.subject”, subject);
params.append(“message.author”, '“test123”);
var x = document.getElementById(“upload”);
for (var i = 0; i < x.files.length; i++) {
params.append(“message.upload”, x.files[i]);

}
var $ajaxOptions = {
url: urlString+“?t=”+Math.random(),
headers: { “cache-control”: “no-cache” },
async:false,
type: “POST”,
enctype: ‘multipart/form-data’,
processData: false,
contentType: false,
data: params,
dataType: “JSON”
};
$.ajax($ajaxOptions).always(function (jqXHR, textStatus, errorMessage) {
var redirectURL=jqXHR.response.message.view_href;
window.location.href=redirectURL;
} else {
alert(jqXHR.status + ‘:’ + errorMessage);
posted = false;
}
});

You may want to look at https://cmlenz.github.io/jquery-iframe-transport/ which handles the cross-browser compatibility issues with file uploads via ajax.

1 Like

Thanks for ur reply, can you please guide in existing code what’s the issue.

I’m not sure which browsers support multipart/form-data ajax submissions but I know that it’s limited support. That’s why when I’ve needed that in the past I have used that plugin I linked to which does the old fashioned submissions using a <form /> to do the do posting.

Need more help

What part of this page are you having trouble with?

Seems pretty clear to me and it has examples, but that doesn’t mean it’s perfect.

https://cmlenz.github.io/jquery-iframe-transport/

Facing file upload using ajax in safari browser is a issue.

if i remove

enctype: ‘multipart/form-data’,
processData: false,
contentType: false,

and without file upload, regular form element get submitted successfully using ajax.

It doesn’t sound like you have attempted to use my suggestion at all. Please try that out and let us know how you go.

This isssue is resolved, thanks everyone

What was the solution? :slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.