简体   繁体   中英

ASCII to text conversion different on Chrome than Safari or Opera

I'm trying to use String.fromCharCode(parseInt(value)); to convert ascii to text from a hidden field. It works fine on Chrome, Firefox, and IE, but not on Safari or Opera. I tried a simple string such as this: var res = String.fromCharCode(72, 69, 76, 76, 79); and it works fine across browsers. The ascii is converted to HELLO . But when I try something more complicated, it no longer works. I'm wondering if it might be that the ascii is different for different browsers. I could be totally wrong.

Note: by not works, I mean when I do console.log(answer), the answer is garbled. 9ods? appears instead of God's Masterpiece Matthew 15:99 Psalms 129:158 which is what it should be.

Here's a code snippet with that specific part of my code:

var arrHiddenAnswer = $('.hiddenAnswer').val().split(',');
var answer = "";
$.each(arrHiddenAnswer, function(key, value){
    answer += String.fromCharCode(parseInt(value));
});
console.log(answer: "+answer);

Here's the hidden field from the form I'm working with that I get the hidden answer value from:

<input type="hidden" class="hiddenAnswer" name="hiddenAnswer" value="071,111,100,039,115,032,077,097,115,116,101,114,112,105,101,099,101,032,077,097,116,116,104,101,119,032,049,053,058,057,057,032,080,115,097,108,109,115,032,049,050,057,058,049,053,056">

If it helps, here's the test page with what I'm working on: http://playfuldevotions.com/archives/140

Thanks in advance!

Edit: if there's a better way of encrypting an answer then getting its value, please feel free to share.

Supply a radix to parseInt :

> parseInt("071") // oh, leading zero, must be octal!
57
> parseInt("071", 10)
71

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM