javascript - HTML Img's failing to load -
just fun, i'm trying implement "15 puzzle", 16 images (from 1 music photo) instead.
the thing split 2 scripts / sides. 1 python cgi script perform last.fm query + splitting image in y x z chunks. when python script finishes outputs json string contains location (on server), extension etc.
{"succes": true, "content": {"nrofpieces": 16, "size": {"width": 1096, "height": 961}, "directoryname": "mako", "extension": "jpeg"}}
on other side html, js, (css) combo query cgi script images.
$(document).ready(function () { var artiest = $("#artiest") var rijen = $("#rijen") var kolommen = $("#kolommen") var speelveld = $("#speelveld") var search = $("#search") $("#buttonclick").click(function () { var artiestz = artiest.val() var rijenz = rijen.val() var kolommenz = kolommen.val() $.getjson("http://localhost:8000/cgi-bin/cgiscript.py", "artiest=" + artiestz + "&rijen=" + rijenz + "&kolommen=" + kolommenz, function (jsonsring) { console.log("hiiiiii") if (jsonsring.succes === true){ console.log(jsonsring) var baseurl = "http://localhost:8000/" var extension = jsonsring.content.extension var url = baseurl + jsonsring.content.directoryname + "/" var amountx = rijenz var amounty = kolommenz (var = 0; < amountx; += 1){ (var p = 0; p < amounty; p += 1){ console.log("hi") var doc = new image doc.setattribute("src", url + jsonsring.content.directoryname + + "_" + p + "." +extension) document.getelementbyid("speelveld").appendchild(doc) } } }else { // search failed. deal it. } }) })
})
where various id's link various html elements. (text fields & buttons & div's).
beneath screenshot of full folder contains image files.
now, coming point. html img tags src seem correct, yet. images don't load, yet other do. noticed images failed load in 2s intervals. there kind of timeout, or so?
all being ran local machine, disk speed , cpu shouldn't affect matter. also, understand: call making img tags etc done in callback getjson, meaning it'll run when getjson has finished / had reply.
does great stackoverflow community have idea what's happening here?
to share knowledge/experiences great stackoverflow community,
small backstory
after progressing bit further project started run various issues going json parsing not having allow-control-allow-origin: *
headers, making hard ajax request (client ==> python cgi) done.
in meantime started dev'ing on main desktop (which reason either has massive issues python versioning or has none). due terminal on desktop having python 3.4+ , there no module cgihttpserver. after small amount of digging, found cgihttpserver had been transfered http.server, yet when running plain old python -m http.server
, noticed cgi script wouldn't run. display. ofcourse, forgot option -cgi
.
main solution
the times succesfully using cgihttpserver, had troubles. images wouldn't load described above. suspect module couldn't take decent amount of requests. meaning when y x z requests came in, struggle deliver data. ==> connection refused.
since switching python -m http.server -cgi
, no problems ever. working on bootstrap grid images!
thx @lashane , @ruud.
Comments
Post a Comment