简体   繁体   中英

jquery fileupload cross domain

I have a small problem i need to create a fileuploader to a remote server using jquery Blueimp Fileupload , if i work locally for testing it is working perfectly now when I tested it on live, Im having a problem with cross origin resource sharing.

Now, how can I retrieve the json response from another domain without using jsonp because I tried jsonp and it does not work with the fileuploader so now I want to do it using json alone and get the response that i need if thats possible

I also tried putting callback=? at the end of url .. also did not work

Or if its possible how can I integrate jsonp with this fileuploader

$( '#fileuploader' ).fileupload( {
        sequentialUploads: true, 
        url: 'http://www.domain.com/test/upload?callback=?',
        dropZone: $( '#fileuploader' )
} );

Server Side this is on another domain

echo json_encode( array( 'test' => 'value1') );

Also: i am not allowed to use ftp / curl for this.. thanks

you can allow CORS request at server as:

   header("Access-Control-Allow-Origin:*");
   header("Access-Control-Allow-Methods: POST, GET, OPTIONS");

When CORS is enabled at server, Ajax first send OPTIONS request to detect whether server allow CORS request or not. if enabled, it send actual request.

If you have allowed the CORS policy on the remote server as suggest above and you still get the Cross Origin error it could be that there is something else not working in your code. Many times Firebug or similar tools show a Cross Origin error and in reality it was a 404 or something else. First question to answer is if you actually at a CORS pre-flight request/response. That's your permission ticket. Check out these posts here here and here

You might consider using the iframe transport option . This will let you keep away from issues with browser that doesn't support cross-domain file uploads, like our old (but still widely used) friend IE 9 or previous versions.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM