skip to Main Content

I am fetching a image url from a placeid of a roblox game via noblox.js the url response is something like this:

{
    "data": [
        {
            "targetId": 4111023553,
            "state": "Completed",
            "imageUrl": "https://tr.rbxcdn.com/6c6e12c567342835b16e787d9ea60467/50/50/Image/Png",
            "version": null
        }
    ]
}

The img.src when I try to set the image to the imageUrl from the fetched data it doesn’t properly display the imageUrl image it just displays a placeholder image. Note this is an electron app. It could be a fetching error. However, I use this same bit of code in a different part of my code and works perfectally normal it only fails here.

var imageUrl

function GetGameIcon(placeid) {
    var gameInfo = `https://thumbnails.roblox.com/v1/places/gameicons?placeIds=${placeid}&returnPolicy=PlaceHolder&size=50x50&format=Png&isCircular=false`
    fetch(gameInfo).then(responce => responce.json()).then(data => {
         imageUrl = data.data[0].imageUrl
         imageUrl = imageUrl.replace("50/50", "20/20")

         const img = document.querySelector('img')
         img.src = imageUrl
   })
}

function Run() {
   document.getElementById("gamename").innerHTML = game
   GetGameIcon(placeid)
}

2

Answers


  1. You have copied the path itself that’s wrong way. You have to use dot path as root it will appear as you saved your path.

    Login or Signup to reply.
  2. You have to declare img variable from const to var.

    const img = document.querySelector(‘img’)

    var img = document.querySelector(‘img’)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search