1

I am trying to get Petrol Prices from Global Petrol Prices, their API has XML as response. This is code to get XML Response.

var apiURL =
  'https://www.globalpetrolprices.com/api/getGasXML_weekly.php?gasoline_diesel=2&rate=USD&countries=52&p=765982d8f9f5f25d4dafc14aa38922f2';

fetch(apiURL, {
  method: 'GET',
  mode: 'no-cors'
})
  .then(response => response.text())
  .then(str => new window.DOMParser().parseFromString(str, 'text/xml'))
  .then(data => console.log(data));

But I am not getting any response from the code. However, when I visit to that URL I get XML response like this.

<mtc:data><mtc:country id="DZ" country_name="Algeria">
 <mtc:gas_type id="diesel">0.2</mtc:gas_type>
 <mtc:year>2018</mtc:year>
 <mtc:week>34</mtc:week>
 <mtc:week_start>20-08-2018</mtc:week_start>
 <mtc:currency>USD</mtc:currency></mtc:country>
</mtc:data>

Can anyone help me with this? TIA

Luzan Baral
  • 3,678
  • 5
  • 37
  • 68

1 Answers1

0

If you send a request with JavaScript on the client side, you get an error. No 'Access-Control-Allow-Origin' header is present on the requested resource. you will get the error

You have to do by Server side

Emre BOSTAN
  • 33
  • 1
  • 7