1

I cant understand what mean that errors.

This is my component:

import React, { Component } from 'react';
import { Text, View } from 'react-native';
import axios from 'axios';

class AlbumList extends Component {

 componentWillMount() {
 axios.get('https://rallycoding.herokuapp.com/api/music_albums')
 .then(response => console.log(response));
 }
 render() {
   return (
    <View>
     <Text>AlbumList!</Text>
    </View>
);
 }
}
 export default AlbumList;

This is my Errors:

enter image description here

@ deltaUrlToBlobUrl.js:29 Show:

enter image description here

(index):185 show (I added ";" but dont help) :

enter image description here

Andrew
  • 26,706
  • 9
  • 85
  • 101
Sura
  • 37
  • 4
  • Possible duplicate of [No 'Access-Control-Allow-Origin' header is present on the requested resource—when trying to get data from a REST API](https://stackoverflow.com/questions/43871637/no-access-control-allow-origin-header-is-present-on-the-requested-resource-whe) – Patrick Hund Mar 03 '19 at 14:51
  • call `axios` in `componentDidMount()` instead of `componentWillMount()` – Jalal Mar 03 '19 at 14:55
  • calling it in `componentDidUpdate` won't help as this is a CORS problem as stated in the comment before – davbuc Mar 03 '19 at 14:56
  • i see, and i should say `componentDidMount` instead of `componentDidUpdate` – Jalal Mar 03 '19 at 15:01

1 Answers1

3

Try to call your api request in componentDidMount(). Your API endpoint working fine. here attached the screen shot of your desired solution.

enter image description here

Irfan Alam
  • 311
  • 1
  • 9
  • @ Irfan Alam I solved this but after I got errors like :...................Failed to load resource: the server responded with a status of 500 (Internal Server Error) and:..... Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0 – Sura Mar 03 '19 at 20:05
  • kindly elaborate the error, so that we able to solve the issue. or contact me on skype (irfan.alam42) – Irfan Alam Mar 04 '19 at 06:57