0

I am trying to call open weather api end point to retrieve weather data. I am using ajax call to do so . But I am unable to retrieve data ending up with error

Refused to execute script from 'http://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=b22143fb388a8a942c07908dad1c1c90&callback=jQuery110200018843492128348682_1517942950649&_=1517942950650' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled.

Screenshot of the code:

Code

Jako
  • 944
  • 14
  • 33

1 Answers1

0

After looking at that API endpoint, you will need to build a proxy file on your server.

You can leave your ajax request alone, but point it to /your/domain/file.php.

From there, inside the PHP file, make a backend server-to-server request and return the results to the client.

This will bypass the CORS restriction and the improper Mime type (chrome is preventing it from loading)

Tallboy
  • 12,847
  • 13
  • 82
  • 173
  • Failed to load http://samples.openweathermap.org/data/2.5/weather?q=Muzaffarabad&appid=ea7cda5080a1c8d5daaed5d14756d3c6: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:27481' is therefore not allowed access. – Muhammad Awais Feb 06 '18 at 19:59
  • when using without jsonp genrates above error and cache true does not work – Muhammad Awais Feb 06 '18 at 20:00
  • You probably will need to build a proxy on your server which proxies the request from the same domain to bypass CORS. After looking at it, their jsonp doesn't return the proper MIME type and that wont work in chrome – Tallboy Feb 06 '18 at 20:07