jajajaja
PyScript Image Fetch Example
Fetch and Display Images with PyScript
import js
from js import XMLHttpRequest
def fetch_image(url):
"""Fetch image using XMLHttpRequest and return a data URL."""
xhr = XMLHttpRequest.new()
xhr.open("GET", url, True)
xhr.responseType = "arraybuffer"
def onload(event):
if xhr.status == 200:
blob = js.Blob.new([xhr.response], {"type": "image/jpeg"})
url = js.URL.createObjectURL(blob)
js.document.getElementById('image-container').innerHTML += f'
'
else:
print(f"Failed to fetch {url}")
xhr.onload = onload
xhr.send()
def fetch_and_display_images(event):
image_links = [
"https://sv2.imgkc2.my.id/wp-content/img/J/Jitsu-wa-Ryouomoi-Kamo-Shirenai/002/001.jpeg",
"https://sv2.imgkc2.my.id/wp-content/img/J/Jitsu-wa-Ryouomoi-Kamo-Shirenai/002/002.jpeg",
"https://sv2.imgkc2.my.id/wp-content/img/J/Jitsu-wa-Ryouomoi-Kamo-Shirenai/002/003.jpeg"
]
# Clear previous images
js.document.getElementById('image-container').innerHTML = ""
for link in image_links:
fetch_image(link)
js.document.getElementById('fetch-button').addEventListener('click', fetch_and_display_images)
Tidak ada komentar:
Posting Komentar