Making jQuery.ajax request through a proxy server

Ziink picture Ziink · May 3, 2014 · Viewed 17.6k times · Source

I'm writing a Chrome extension. If you make jQuery.ajax request for a regular http page from within a page served via https, then the request is blocked by Chrome. I was wondering if I could fetch the requested page using a secure proxy.

So, is it possible to use a generic proxy server for some jQuery.ajax request? If so, how? Note, changing the proxy setting of the browser is not an option.

Answer

fjc picture fjc · May 3, 2014

Yes, it is.

What we did at work was implement a proxy that does exactly that:

  1. It takes web service calls from the same origin, then,
  2. on the server side, maps them to a web service of another origin,
  3. sends them there,
  4. receives the results and
  5. passes them on back to the caller.

This way you can both comply with the same origin policy and work with other origins. However, you will always need a server-side proxy functionality.