code is working while debug, but without not - Javascript / Jquery
up vote
0
down vote
favorite
I have an issue that I don't understand and I have no idea how to fix it, where to look for the cause. When I'm debugin (chrome) every thing is working, but during normal use it dosen't. For me is some kind of Science-Fiction, it would be better for me if it's more Science than Fiction :)
for (var i = 0; i < filteredAddedFiles.length; i++) gif)$/i).test(filteredAddedFiles[i].name))
(function (file)
var reader = new FileReader();
var blob = b64toBlob(file.base64.replace('data:image/jpeg;base64,', ''), file.type);
reader.addEventListener("load", function ()
console.log(this);
var image = new Image();
image.src = window.URL.createObjectURL(blob);
image.onload = function ()
preview.innerHTML += drawHtml(image, file)
;
//I tried:
//(function (b)
// var image = new Image();
// image.addEventListener("load", function ()
// preview.innerHTML += drawHtml(this, file);
// //window.URL.revokeObjectURL(image.src);
// );
// image.src = window.URL.createObjectURL(b);
//)(blob);
);
reader.readAsDataURL(blob);
)(filteredAddedFiles[i]);
else
errors += filteredAddedFiles[i].name + " Unsupported Image extensionn";
here I attached a short movie that shows how its working
link to movie
not working - I mean - it looks like the all thing inside for
dosen't executed
EDIT: 1
@Teemu - I turn on logs in chrome console and all console.log
's appear
@Katie.Sun - now the above for
- console.log(filteredAddedFiles.length);
is 0
- but when I'm debuging code the same console.log(filteredAddedFiles.length);
have values !
EDIT: 2
@Matti PricefilteredAddedFiles
- is the result of custom logic of page, filtering,
validation etc.
Everything starts here:
addedFiles = added(files); // files - FileList from input this is a read only array of obj
function added(from)
var out = ;
for (var i = 0; i < from.length; i++)
(function (obj)
var readerBase64 = new FileReader();
readerBase64.addEventListener("load", function ()
var fileBase64 = readerBase64.result;
var row = name: obj.name, size: obj.size, type: obj.type, base64: fileBase64
out.push(row);
);
readerBase64.readAsDataURL(obj);
)(from[i]);
return out;
then addedFiles
- do something farther and transform into filteredAddedFiles
later. what I found in added
function? during debug there is an length
value witch is correct, but when I opened the __proto__: Array(0)
I found length
property = 0.
Should this length
value be equal to the value from above length
?
The second thing:
I have to admit that I don't have enough knowledge aboute addEventListener
. Are there any queues here or some thread etc?
EDIT: 3
After last @Teemu comment I made some changes (I had to read a lot aboute promisses etc:)), but output is the same console.log("out resolve", out);
shows a array of object, but console.log("out.length then", out.length);
shows 0
and the small blue i-icon
show msg - Value below evaluated just now
var out = ;
for (var i = 0; i < files.length; i++)
fillArray(files[i], out);
console.log("out resolve", out);
console.log("out.length then", out.length);
function fillArray(obj, out) {
return new Promise(function (resolve, reject)
var readerBase64 = new FileReader();
readerBase64.addEventListener("load", function ()
var fileBase64 = readerBase64.result;
var row = name: obj.name, size: obj.size, type: obj.type, out.push(row);
resolve(out);
);
readerBase64.readAsDataURL(obj);
);
After I posted the edit above I relized that I just create promise
, I forgot to call `promise
, but this is not important, because 90% of my code has been changed because of this topic and the answer of the Golden Person @Kaiido
URL.createObjectURL() - is synchronous. You don't need your Promise wrapping event handlers hell, all can be done in a single loop.
In my case, this is a better solution than a filereader, I have to upload only images, and with some restrictions thanks to which I don't have to worry about freeze the Internet browser, because of the synchronous
nature of createObjectURL()
Thank you for your help and commitment
javascript jquery google-chrome debugging
|
show 11 more comments
up vote
0
down vote
favorite
I have an issue that I don't understand and I have no idea how to fix it, where to look for the cause. When I'm debugin (chrome) every thing is working, but during normal use it dosen't. For me is some kind of Science-Fiction, it would be better for me if it's more Science than Fiction :)
for (var i = 0; i < filteredAddedFiles.length; i++) gif)$/i).test(filteredAddedFiles[i].name))
(function (file)
var reader = new FileReader();
var blob = b64toBlob(file.base64.replace('data:image/jpeg;base64,', ''), file.type);
reader.addEventListener("load", function ()
console.log(this);
var image = new Image();
image.src = window.URL.createObjectURL(blob);
image.onload = function ()
preview.innerHTML += drawHtml(image, file)
;
//I tried:
//(function (b)
// var image = new Image();
// image.addEventListener("load", function ()
// preview.innerHTML += drawHtml(this, file);
// //window.URL.revokeObjectURL(image.src);
// );
// image.src = window.URL.createObjectURL(b);
//)(blob);
);
reader.readAsDataURL(blob);
)(filteredAddedFiles[i]);
else
errors += filteredAddedFiles[i].name + " Unsupported Image extensionn";
here I attached a short movie that shows how its working
link to movie
not working - I mean - it looks like the all thing inside for
dosen't executed
EDIT: 1
@Teemu - I turn on logs in chrome console and all console.log
's appear
@Katie.Sun - now the above for
- console.log(filteredAddedFiles.length);
is 0
- but when I'm debuging code the same console.log(filteredAddedFiles.length);
have values !
EDIT: 2
@Matti PricefilteredAddedFiles
- is the result of custom logic of page, filtering,
validation etc.
Everything starts here:
addedFiles = added(files); // files - FileList from input this is a read only array of obj
function added(from)
var out = ;
for (var i = 0; i < from.length; i++)
(function (obj)
var readerBase64 = new FileReader();
readerBase64.addEventListener("load", function ()
var fileBase64 = readerBase64.result;
var row = name: obj.name, size: obj.size, type: obj.type, base64: fileBase64
out.push(row);
);
readerBase64.readAsDataURL(obj);
)(from[i]);
return out;
then addedFiles
- do something farther and transform into filteredAddedFiles
later. what I found in added
function? during debug there is an length
value witch is correct, but when I opened the __proto__: Array(0)
I found length
property = 0.
Should this length
value be equal to the value from above length
?
The second thing:
I have to admit that I don't have enough knowledge aboute addEventListener
. Are there any queues here or some thread etc?
EDIT: 3
After last @Teemu comment I made some changes (I had to read a lot aboute promisses etc:)), but output is the same console.log("out resolve", out);
shows a array of object, but console.log("out.length then", out.length);
shows 0
and the small blue i-icon
show msg - Value below evaluated just now
var out = ;
for (var i = 0; i < files.length; i++)
fillArray(files[i], out);
console.log("out resolve", out);
console.log("out.length then", out.length);
function fillArray(obj, out) {
return new Promise(function (resolve, reject)
var readerBase64 = new FileReader();
readerBase64.addEventListener("load", function ()
var fileBase64 = readerBase64.result;
var row = name: obj.name, size: obj.size, type: obj.type, out.push(row);
resolve(out);
);
readerBase64.readAsDataURL(obj);
);
After I posted the edit above I relized that I just create promise
, I forgot to call `promise
, but this is not important, because 90% of my code has been changed because of this topic and the answer of the Golden Person @Kaiido
URL.createObjectURL() - is synchronous. You don't need your Promise wrapping event handlers hell, all can be done in a single loop.
In my case, this is a better solution than a filereader, I have to upload only images, and with some restrictions thanks to which I don't have to worry about freeze the Internet browser, because of the synchronous
nature of createObjectURL()
Thank you for your help and commitment
javascript jquery google-chrome debugging
You should write down what is not working. Are there any errors in the console?
– Andy
Nov 8 at 19:16
1
Then the first thing to do is to check the value offilteredAddedFiles.length
before the loop.
– Teemu
Nov 8 at 19:23
1
@szkut how are you calling this part of your code? if you just do aconsole.log("here");
before the for loop and run it normally, what happens? Because if the answer is nothing then whatever is causing this problem is not in the block of code you posted
– Katie.Sun
Nov 8 at 19:34
1
Make sure the logs are shown, "Default" should be selected from "Log levels".
– Teemu
Nov 8 at 19:53
1
Where isfilteredAddedFiles
coming from?
– Matti Price
Nov 8 at 21:53
|
show 11 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have an issue that I don't understand and I have no idea how to fix it, where to look for the cause. When I'm debugin (chrome) every thing is working, but during normal use it dosen't. For me is some kind of Science-Fiction, it would be better for me if it's more Science than Fiction :)
for (var i = 0; i < filteredAddedFiles.length; i++) gif)$/i).test(filteredAddedFiles[i].name))
(function (file)
var reader = new FileReader();
var blob = b64toBlob(file.base64.replace('data:image/jpeg;base64,', ''), file.type);
reader.addEventListener("load", function ()
console.log(this);
var image = new Image();
image.src = window.URL.createObjectURL(blob);
image.onload = function ()
preview.innerHTML += drawHtml(image, file)
;
//I tried:
//(function (b)
// var image = new Image();
// image.addEventListener("load", function ()
// preview.innerHTML += drawHtml(this, file);
// //window.URL.revokeObjectURL(image.src);
// );
// image.src = window.URL.createObjectURL(b);
//)(blob);
);
reader.readAsDataURL(blob);
)(filteredAddedFiles[i]);
else
errors += filteredAddedFiles[i].name + " Unsupported Image extensionn";
here I attached a short movie that shows how its working
link to movie
not working - I mean - it looks like the all thing inside for
dosen't executed
EDIT: 1
@Teemu - I turn on logs in chrome console and all console.log
's appear
@Katie.Sun - now the above for
- console.log(filteredAddedFiles.length);
is 0
- but when I'm debuging code the same console.log(filteredAddedFiles.length);
have values !
EDIT: 2
@Matti PricefilteredAddedFiles
- is the result of custom logic of page, filtering,
validation etc.
Everything starts here:
addedFiles = added(files); // files - FileList from input this is a read only array of obj
function added(from)
var out = ;
for (var i = 0; i < from.length; i++)
(function (obj)
var readerBase64 = new FileReader();
readerBase64.addEventListener("load", function ()
var fileBase64 = readerBase64.result;
var row = name: obj.name, size: obj.size, type: obj.type, base64: fileBase64
out.push(row);
);
readerBase64.readAsDataURL(obj);
)(from[i]);
return out;
then addedFiles
- do something farther and transform into filteredAddedFiles
later. what I found in added
function? during debug there is an length
value witch is correct, but when I opened the __proto__: Array(0)
I found length
property = 0.
Should this length
value be equal to the value from above length
?
The second thing:
I have to admit that I don't have enough knowledge aboute addEventListener
. Are there any queues here or some thread etc?
EDIT: 3
After last @Teemu comment I made some changes (I had to read a lot aboute promisses etc:)), but output is the same console.log("out resolve", out);
shows a array of object, but console.log("out.length then", out.length);
shows 0
and the small blue i-icon
show msg - Value below evaluated just now
var out = ;
for (var i = 0; i < files.length; i++)
fillArray(files[i], out);
console.log("out resolve", out);
console.log("out.length then", out.length);
function fillArray(obj, out) {
return new Promise(function (resolve, reject)
var readerBase64 = new FileReader();
readerBase64.addEventListener("load", function ()
var fileBase64 = readerBase64.result;
var row = name: obj.name, size: obj.size, type: obj.type, out.push(row);
resolve(out);
);
readerBase64.readAsDataURL(obj);
);
After I posted the edit above I relized that I just create promise
, I forgot to call `promise
, but this is not important, because 90% of my code has been changed because of this topic and the answer of the Golden Person @Kaiido
URL.createObjectURL() - is synchronous. You don't need your Promise wrapping event handlers hell, all can be done in a single loop.
In my case, this is a better solution than a filereader, I have to upload only images, and with some restrictions thanks to which I don't have to worry about freeze the Internet browser, because of the synchronous
nature of createObjectURL()
Thank you for your help and commitment
javascript jquery google-chrome debugging
I have an issue that I don't understand and I have no idea how to fix it, where to look for the cause. When I'm debugin (chrome) every thing is working, but during normal use it dosen't. For me is some kind of Science-Fiction, it would be better for me if it's more Science than Fiction :)
for (var i = 0; i < filteredAddedFiles.length; i++) gif)$/i).test(filteredAddedFiles[i].name))
(function (file)
var reader = new FileReader();
var blob = b64toBlob(file.base64.replace('data:image/jpeg;base64,', ''), file.type);
reader.addEventListener("load", function ()
console.log(this);
var image = new Image();
image.src = window.URL.createObjectURL(blob);
image.onload = function ()
preview.innerHTML += drawHtml(image, file)
;
//I tried:
//(function (b)
// var image = new Image();
// image.addEventListener("load", function ()
// preview.innerHTML += drawHtml(this, file);
// //window.URL.revokeObjectURL(image.src);
// );
// image.src = window.URL.createObjectURL(b);
//)(blob);
);
reader.readAsDataURL(blob);
)(filteredAddedFiles[i]);
else
errors += filteredAddedFiles[i].name + " Unsupported Image extensionn";
here I attached a short movie that shows how its working
link to movie
not working - I mean - it looks like the all thing inside for
dosen't executed
EDIT: 1
@Teemu - I turn on logs in chrome console and all console.log
's appear
@Katie.Sun - now the above for
- console.log(filteredAddedFiles.length);
is 0
- but when I'm debuging code the same console.log(filteredAddedFiles.length);
have values !
EDIT: 2
@Matti PricefilteredAddedFiles
- is the result of custom logic of page, filtering,
validation etc.
Everything starts here:
addedFiles = added(files); // files - FileList from input this is a read only array of obj
function added(from)
var out = ;
for (var i = 0; i < from.length; i++)
(function (obj)
var readerBase64 = new FileReader();
readerBase64.addEventListener("load", function ()
var fileBase64 = readerBase64.result;
var row = name: obj.name, size: obj.size, type: obj.type, base64: fileBase64
out.push(row);
);
readerBase64.readAsDataURL(obj);
)(from[i]);
return out;
then addedFiles
- do something farther and transform into filteredAddedFiles
later. what I found in added
function? during debug there is an length
value witch is correct, but when I opened the __proto__: Array(0)
I found length
property = 0.
Should this length
value be equal to the value from above length
?
The second thing:
I have to admit that I don't have enough knowledge aboute addEventListener
. Are there any queues here or some thread etc?
EDIT: 3
After last @Teemu comment I made some changes (I had to read a lot aboute promisses etc:)), but output is the same console.log("out resolve", out);
shows a array of object, but console.log("out.length then", out.length);
shows 0
and the small blue i-icon
show msg - Value below evaluated just now
var out = ;
for (var i = 0; i < files.length; i++)
fillArray(files[i], out);
console.log("out resolve", out);
console.log("out.length then", out.length);
function fillArray(obj, out) {
return new Promise(function (resolve, reject)
var readerBase64 = new FileReader();
readerBase64.addEventListener("load", function ()
var fileBase64 = readerBase64.result;
var row = name: obj.name, size: obj.size, type: obj.type, out.push(row);
resolve(out);
);
readerBase64.readAsDataURL(obj);
);
After I posted the edit above I relized that I just create promise
, I forgot to call `promise
, but this is not important, because 90% of my code has been changed because of this topic and the answer of the Golden Person @Kaiido
URL.createObjectURL() - is synchronous. You don't need your Promise wrapping event handlers hell, all can be done in a single loop.
In my case, this is a better solution than a filereader, I have to upload only images, and with some restrictions thanks to which I don't have to worry about freeze the Internet browser, because of the synchronous
nature of createObjectURL()
Thank you for your help and commitment
javascript jquery google-chrome debugging
javascript jquery google-chrome debugging
edited Nov 10 at 20:20
asked Nov 8 at 19:14
szkut
7110
7110
You should write down what is not working. Are there any errors in the console?
– Andy
Nov 8 at 19:16
1
Then the first thing to do is to check the value offilteredAddedFiles.length
before the loop.
– Teemu
Nov 8 at 19:23
1
@szkut how are you calling this part of your code? if you just do aconsole.log("here");
before the for loop and run it normally, what happens? Because if the answer is nothing then whatever is causing this problem is not in the block of code you posted
– Katie.Sun
Nov 8 at 19:34
1
Make sure the logs are shown, "Default" should be selected from "Log levels".
– Teemu
Nov 8 at 19:53
1
Where isfilteredAddedFiles
coming from?
– Matti Price
Nov 8 at 21:53
|
show 11 more comments
You should write down what is not working. Are there any errors in the console?
– Andy
Nov 8 at 19:16
1
Then the first thing to do is to check the value offilteredAddedFiles.length
before the loop.
– Teemu
Nov 8 at 19:23
1
@szkut how are you calling this part of your code? if you just do aconsole.log("here");
before the for loop and run it normally, what happens? Because if the answer is nothing then whatever is causing this problem is not in the block of code you posted
– Katie.Sun
Nov 8 at 19:34
1
Make sure the logs are shown, "Default" should be selected from "Log levels".
– Teemu
Nov 8 at 19:53
1
Where isfilteredAddedFiles
coming from?
– Matti Price
Nov 8 at 21:53
You should write down what is not working. Are there any errors in the console?
– Andy
Nov 8 at 19:16
You should write down what is not working. Are there any errors in the console?
– Andy
Nov 8 at 19:16
1
1
Then the first thing to do is to check the value of
filteredAddedFiles.length
before the loop.– Teemu
Nov 8 at 19:23
Then the first thing to do is to check the value of
filteredAddedFiles.length
before the loop.– Teemu
Nov 8 at 19:23
1
1
@szkut how are you calling this part of your code? if you just do a
console.log("here");
before the for loop and run it normally, what happens? Because if the answer is nothing then whatever is causing this problem is not in the block of code you posted– Katie.Sun
Nov 8 at 19:34
@szkut how are you calling this part of your code? if you just do a
console.log("here");
before the for loop and run it normally, what happens? Because if the answer is nothing then whatever is causing this problem is not in the block of code you posted– Katie.Sun
Nov 8 at 19:34
1
1
Make sure the logs are shown, "Default" should be selected from "Log levels".
– Teemu
Nov 8 at 19:53
Make sure the logs are shown, "Default" should be selected from "Log levels".
– Teemu
Nov 8 at 19:53
1
1
Where is
filteredAddedFiles
coming from?– Matti Price
Nov 8 at 21:53
Where is
filteredAddedFiles
coming from?– Matti Price
Nov 8 at 21:53
|
show 11 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53214645%2fcode-is-working-while-debug-but-without-not-javascript-jquery%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You should write down what is not working. Are there any errors in the console?
– Andy
Nov 8 at 19:16
1
Then the first thing to do is to check the value of
filteredAddedFiles.length
before the loop.– Teemu
Nov 8 at 19:23
1
@szkut how are you calling this part of your code? if you just do a
console.log("here");
before the for loop and run it normally, what happens? Because if the answer is nothing then whatever is causing this problem is not in the block of code you posted– Katie.Sun
Nov 8 at 19:34
1
Make sure the logs are shown, "Default" should be selected from "Log levels".
– Teemu
Nov 8 at 19:53
1
Where is
filteredAddedFiles
coming from?– Matti Price
Nov 8 at 21:53