2

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

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Nope, still does not work if I add it on server side
1

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

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.