1

I have a SlingServlet which I am trying to access by making ajax call from html outside of AEM.At first it works but now I am getting following error:

test.html:1 XMLHttpRequest cannot load http://localhost:4502/bin/DamHandlerr.html?imgURL=http://s3.amazonaws.com/f…iles-aviary-prod-us-east-1/2016-05-24/3dfa830ede7b44c4a88e872b22875c85.png. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

Can anyone guide me here?

ArK
  • 20,698
  • 67
  • 109
  • 136
  • This [SO post](http://stackoverflow.com/questions/27985193/how-to-enable-cors-in-crxde-lite-aem) has a pointer to enable CORS in AEM using a custom Filter – Abhishek May 25 '16 at 05:30

1 Answers1

0

This type of request is called CORS (Cross Origin Resource Sharing). If you want the AJAX client host/port to call another host/port URL, the server needs to add appropriate headers in response to tell client that call to different host server is allowed.

You would need to add Access-Control-Allow-Origin header in response to allow AJAX client to successfully access the different origin URL.

Sometimes in modern browsers AJAX client, makes additional request to check if resource is safe to access called Pre-flight Requests, in that case additional headers would be needed in response as listed in the link and this link.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Sandeep Kumar
  • 1,758
  • 1
  • 22
  • 39