Enjoy an ad free experience by logging in. Not a member yet? Register.
|
|
Results 1 to 3 of 3
-
11-21-2015, 07:44 PM #1New to the CF scene
- Join Date
- Nov 2015
- Posts
- 1
- Thanks
- 0
- Thanked 0 Times in 0 Posts
XMLHttpRequest to get a php script loading a thumbnail image
Hello @all,
first off: I'm a German php programmer with my first steps in javascript. So sorry if I make some mistakes in explaining.
My issue: the src is not filled:
In my html file I have the following code:
To debug I use netbeans / chrome netbeans connector:Code:<script> ... function fillNavBar() { ... elImg.src = getThumbnail(strFileName,cx*dpr,cy*dpr); ... } function getThumbnail(filename,width,height){ //return filename; var oImg = new XMLHttpRequest(); oImg.responseType = "blob"; oImg.onreadystatechange = function() { if (oImg.readyState == 4 && oImg.status == 200) { var blob = new Blob([oImg.response],{type:'image/jpeg'}); var urlCreator = window.URL || window.webkitURL; var imageUrl = urlCreator.createObjectURL( blob ); return imageUrl; } }; oImg.open("GET","./panos/create_thumbnail.php?src=" + filename + "&width=" + width + "&height=" + height , true); // `false` makes the request synchronous oImg.send(); }
- The value of var blob is BLOB. Is this correct or the the first problem!???
- The value of var imageURL is "blob:http%3A//localhost%3A8383/5066ed81-2668-4ab7-9b60-be912cc4e20a".
The called php Skript sends an image to the browser. So do I have to strip the imageURL???
Thx in advance
maen
-
11-22-2015, 02:36 AM #2New Coder
- Join Date
- Sep 2014
- Posts
- 87
- Thanks
- 0
- Thanked 11 Times in 11 Posts
First, Is there any reason why you could not just do:
You can always resize the image using "elImg.width = whatever, elImg.height = whatever" or the mimetype and dimension could be returned by create_thumbnail.php.PHP Code:elImg.src = "./panos/create_thumbnail.php?src=" + whatever;
instead of
elImg.src = getThumbnail(strFileName,cx*dpr,cy*dpr);
in any case, if you are using synchronous (not recommended) request, then don't do oImg.onreadystatechange. Instead, just process the response after the send.
With synchronous request, I am not sure if the returned status is in oImg.status.PHP Code:oImg.open("GET","./panos/create_thumbnail.php?src=" + filename + "&width=" + width + "&height=" + height , true);
oImg.send();
if (oImg.status == 200) {
var blob = new Blob([oImg.response],{type:'image/jpeg'});
var urlCreator = window.URL || window.webkitURL;
var imageUrl = urlCreator.createObjectURL( blob );
return imageUrl;
}
else {
alert("response -> " oImg.status);
return null;
-
11-22-2015, 01:33 PM #3Senior Coder
- Join Date
- Aug 2010
- Posts
- 1,103
- Thanks
- 30
- Thanked 241 Times in 239 Posts
getThumbnail does not return anything
do not 'return' from onreadystatechange
instead supply a function to
be called upon completion
blob and URL are native in Microsoft EdgeCode:getThumbnail(strFileName,cx*dpr,cy*dpr,fillNavBar); function fillNavBar(arg) { ... elImg.src = arg; ... } function getThumbnail(filename,width,height,cFunc){ //return filename; var oImg = new XMLHttpRequest(); oImg.responseType = "blob"; oImg.onreadystatechange = function() { if (oImg.readyState == 4 && oImg.status == 200) { var blob = new Blob([oImg.response],{type:'image/jpeg'}); var urlCreator = window.URL || window.webkitURL; var imageUrl = urlCreator.createObjectURL( blob ); cFunc( imageUrl ); } }; oImg.open("GET","./panos/create_thumbnail.php?src=" + filename + "&width=" + width + "&height=" + height , true); // `false` makes the request synchronous oImg.send(); }
but are not available in Internet ExplorerLast edited by DaveyErwin; 11-22-2015 at 04:30 PM.



Reply With Quote
