How to upload image using Ajax request?

How can I work around the same-origin policy to develop AJAX client code for a Google AppEngine site?

  • I'm working with someone who has a Google AppEngine site with a custom API located there. I need to write some AJAX Javascript to interface with the custom API on the site, but I'm getting stonewalled by the same-origin policy. JSONP will be of no use because you can't get an error callback from a failed AJAX request (it doesn't use XMLHTTPRequest). I am using JQuery to make the requests. Apparently Google AppEngine has a terrible caveat that you can't individually upload single files for testing, so I can't fix this problem by developing directly on the API's proper domain. I'm on a MAC and I have heard you can set up some kind of proxy to get around this, I have no idea even where to start with that, and don't want to if I don't absolutely have to. What is the best way to avoid this same-origin policy for development??

  • Answer:

    Well the easiest would be to develop locally, running the site in the App Engine launcher on your mac. If that's not possible but you can get the client to edit his code, you could ask him to add a header (see http://enable-cors.org/) : Access-Control-Allow-Origin: *If again that's not possible you could just run your browser with security disabled to debug your code. For Chrome, launch the browser with this command: /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --disable-web-security

Francois Rejete at Quora Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.