Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Some images wont load from the api.

$
0
0

Hi to everyone, Im new to coding and I need help. I'm trying to do a simple app that reads from an api and the titles all load good but when I click on the title some of them don't show the image and i'm kinda stuck and don't know what to do. Can someone help me with this problem and thanks in advance. Here is my code so you can see and tell me were I have gone wrong.

// Code for accessing the reddit URL
var url = "http://api.reddit.com/r/gaming/";// link to the url
 
var linkWorking = function(){
    console.log("linkSuccess");//console massege to make sure the link is working
    var linkData = JSON.parse(this.responseText);//code to connect to the JSOn data on the api 
    var gamingPosts = linkData.data.children;// code to access the corresponding object of the array from the api
    for(var i=0, p=gamingPosts.length; i<p; i++){
        var postImg = gamingPosts[i].data.url;
        var load = gamingPosts[i].data.thumbnail;
        var postTitle = gamingPosts[i].data.title;
        if(postImg === displayImg, displayImg= load)
        var postView = Ti.UI.createView({
            backgroundColor: "#eaeaea",
            bottom: 4,
            height: Ti.UI.SIZE,
            disImg: postImg
        });
        //label for the title views
        var label = Ti.UI.createLabel({
            text: postTitle,
            color: "black",
            font:{fontSize: 16},
            top: 2,
            bottom: 2,
            left: 12,
            right: 12,
            textAlign: "left",
            height: "auto",
            disImg: postImg
        });
        postView.add(label);
        scrollWin.add(postView);
    }
};
 
var displayImg = function(evt){
    var displayWin = Ti.UI.createWindow({
        backgroundColor: "36c6389",
    });
    var img = Ti.UI.createImageView({
        image: evt.source.disImg
    });
    displayWin.add(img);
 
    displayWin.addEventListener("click", function(){
        this.close();
    });
    displayWin.open();
};
 
scrollWin.addEventListener("click", displayImg);
 
 
//Alert for when the link is broken or not working
var linkError = function(evt){
    alert("Link not working");
    console.log(evt);
};
 
 
var imageLink = Ti.Network.createHTTPClient({
    onload: linkWorking,
    onerror: linkError,
    timeout: 5000
});
 
 
imageLink.open("GET", url);
 
imageLink.send();

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>