0

First I'm not in the web side of our world, so be nice with the backend guy.

A quick background : For a personal need I've developped a google chrome extension. They are basically a webpage loaded in a chrome windows and... yeah that's it. Everything is on the client side (scripts, styles, images, etc...) Only the data are coming from a server through ajax calls. A cron job call a php script every hours to generate two files. One, data.json contains the "latest" datas in a json format. Another one hash.json contain the hash of the data. The client chrome application use local storage. If the remote hash differ from the local one, he simply retrieve the data file from the remote server.

As I have a BizSpark account with Azure my first idea was : Azure Web Site with php for the script, a simple homepage and the generated file and the Azure Scheduler for the jobs.

I've developed everything locally and everything is running fine... but once on the azure plateform I get this error

XMLHttpRequest cannot load http://tso-mc-ws.azurewebsites.net/Core/hash.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:23415' is therefore not allowed access.

But what I really can't understand is that I'm able (and you'll be too) to get the file with my browser... So I just don't get it... I've also tried based on some post I've found on SO and other site to manipulate the config, add extra headers, nothing seems to be working...

Any idea ?

Emmanuel Istace
  • 1,181
  • 12
  • 30

2 Answers2

2

But what I really can't understand is that I'm able (and you'll be too) to get the file with my browser... So I just don't get it

So when you type in http://tso-mc-ws.azurewebsites.net/Core/hash.json in your browser's address bar, it is not a cross-domain request. However when you make an AJAX request from an application which is running in a different domain (http://localhost:23415 in your case), that's a cross-domain request and because CORS is not enabled on your website, you get the error.

As far as enabling CORS is concerned, please take a look at this thread: HTTP OPTIONS request on Azure Websites fails due to CORS. I've never worked with PHP/Azure Websites so I may be wrong with this link but hopefully it should point you in the right direction.

Community
  • 1
  • 1
Gaurav Mantri
  • 100,555
  • 11
  • 158
  • 192
  • Thanks to you Gaurav Mantri, I've already read this article, nothing changed. I've found a way to make it working, take a look at the answer. Thanks for your help ! – Emmanuel Istace Jan 27 '14 at 12:23
0

Ok, will perhap's be little troll answer but not my point (I'm .net consultant so... nothing against MS).

I pick a linux azure virtual machine, installed apache and php, configure apache, set some rights and define the header for the CROS and configure a cron in +/- 30minutes... As my goal is to get it running the problem is solved, it's running.

Emmanuel Istace
  • 1,181
  • 12
  • 30