Sandip Karanjekar Sandip Karanjekar - 1 year ago 210
Ajax Question

Cross domain file upload with jQuery

My code is working fine for same domain.

But when I try it on cross domain with dataType: 'jsonp' & crossDomain: true

Code sample -

var fa = new FormData();

fa.append("upload_pass", document.getElementById("upload_pass").files['0']);

url: 'http://xxx.xx.xx.xx/upload.php',
data: fa,
contentType: false,
processData: false,
dataType: 'jsonp',
crossDomain: true,
type: 'GET',
success: function(data) {

Is there any conceptual understanding gap or coding problem.

Please suggest.

Answer Source

No way to upload file via GET. Even if you will use JSONP. JSONP is working just with GET requests. And you can't upload files with GET request (usually files upload with POST requests).

If you wanna send cross domain POST request to some server, then you should be sure in next case:

That server should send you header Access-Control-Allow-Origin : *. Also you will may be need Access-Control-Allow-Methods: POST header.

If it has those headers, then you are lucky and you can POST your data on this server.

P.S. You can try to use other methods to make valid cross domain request. Nice js library easyXDM for cross domain requests, witch uses different ways to do it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download