0
getData() {
return fetch("http://bitcfeedcms.rf.gd/script.php")
  .then(response => {
    console.log(response);
    response.json();
  })
  .then(responseJson => {
    this.setState({ data: responseJson });
  })
  .catch(error => {
    console.error(error);
  });

}

I also tried by putting ?l=1 like " bitcfeedcms.rf.gd/script.php?l=1 ". The main json file is " bitcfeedcms.rf.gd/feed_data.json ". So i tried "http://bitcfeedcms.rf.gd/feed_data.json?l=1" this too but nothing changed

What i have to do now to get the json data and use it in my app...Please help

5
  • do you see the console.log ? Commented Aug 15, 2017 at 8:23
  • yes ...i checked. Commented Aug 15, 2017 at 16:58
  • Response log is here...bitcfeedcms.rf.gd/1.png Commented Aug 15, 2017 at 17:06
  • 1
    I think your issue lies with the php script. Did you try making the request with Postman? The response comes back as HTML. Commented Aug 15, 2017 at 17:22
  • the postman giving me html as response....see here the response of postman bitcfeedcms.rf.gd/postman%20error.png Commented Aug 22, 2017 at 16:07

3 Answers 3

4

You are using the arrow function wrong. Instead of this:

fetch("http://bitcfeedcms.rf.gd/script.php")
  .then(response => {
    console.log(response);
    response.json();
  })
  .then(responseJson => {
    this.setState({ data: responseJson });
  })

You should return the response.json()

fetch("http://bitcfeedcms.rf.gd/script.php")
   .then(response => {
     console.log(response);
     return response.json();
   })
   .then(responseJson => {
     this.setState({ data: responseJson });
   })

This way you can reach responseJson in the next then.

Also, if your app complains about fetch() network request failed probably it's about Info.plist or Manifest configuration error. See this topic.

For iOS, you can try the same request with this https dummy json url: https://jsonplaceholder.typicode.com/posts/1

Sign up to request clarification or add additional context in comments.

8 Comments

bitcfeedcms.rf.gd/1.png here the response data. it's not giving the correct data....
yes i tried with your code then the (screenshot) result appeared.
bitcfeedcms.rf.gd/feed_data.json?l=1 try with this. Console log both then and tell me the outputs.
bitcfeedcms.rf.gd/up1.png bitcfeedcms.rf.gd/up2.png As you told...i did and the outcome is in the screenshots
check the comment on the question written by @MattyK14
|
0

http://bitcfeedcms.rf.gd/script.php , this link returns multiple sets of JSON.

([{"FeedTitle":"Debotos","FeedDescription":"First Feed Testing....."},{"FeedTitle":"Akash","FeedDescription":"Creating a clan named \"Khulna Sparkers\""},{"FeedTitle":"Ripon","FeedDescription":"My brother and my one of the closest individual"}])

try this . . .

getData() {
 fetch("http://bitcfeedcms.rf.gd/script.php")
  .then(response => {
    console.log(response);
    response.json();
  })
  .then(responseJson => {
        var length = responseJson.length;
        for (var a = 0; a<length;a++) {
            var FeedTitle = responseJson[a].FeedTitle; //<-variable from your response json
            var FeedDescription = responseJson[a].FeedDescription; //<-from your response json
            console.log(FeedTitle);
            console.log(FeedDescription);
        }
  })
  .catch(error => {
    console.error(error);
  });
}

3 Comments

Response log is here bitcfeedcms.rf.gd/1.png other url (for script.php) is responding the same thing like that one
take a look at this line {"FeedTitle":"Akash","FeedDescription":"Creating a clan named \"Khulna Sparkers\""} i guess you have a wrong format of Json. json data must be like this {"var":"value"}
but at offline(via directory path) when i am trying to load that json file it works perfectly....so the json format may be not wrong, it's an array of objects
0

try axios

npm install --save axios

state = {data:[]};
    componentWillMount() {
                 axios.get('http://bitcfeedcms.rf.gd/script.php')
                 .then(response =>this.setState({data:response.data}));
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.