Hmm, not sure.
Are you getting the values from <input> elements?
Try:
var hereWeAre = $(this).val();
On Friday, 17 May 2019 12:13:03 UTC+1, Vlad wrote:
>
> I thought so and tried:
>
> $(".EncodedDescriptionField").each( function(index, element ){
> var hereWeAre = $(this).text();
> var decodedString = atob(hereWeAre);
> console.error(hereWeAre);
> console.error(decodedString);
> });
>
> this brings up an exception:
>
> Uncaught DOMException: Failed to execute 'atob' on 'Window': The string to
> be decoded is not correctly encoded.
>
> I've also double-checked the values - they are correct. For example, when
> I replace with the following:
>
> var decodedString = atob("Q29va2llcyBvbmU=");
>
> it decodes just fine, and the string itself I pick right from there -
> that's the value it has when it throws exception.
>
> Have no slightest clue what could possibly go wrong.
>
>
> On Friday, May 17, 2019 at 7:06:54 AM UTC-4, villas wrote:
>>
>> Maybe you need to iterate through the class elements. See this:
>>
>> https://stackoverflow.com/questions/4735342/jquery-to-loop-through-elements-with-the-same-class
>>
>>
>>
>> On Thursday, 16 May 2019 23:58:28 UTC+1, Vlad wrote:
>>>
>>> Just to clarify:
>>>
>>> the following works perfect for one field by ID (decrypts it back):
>>> var encodedDescription = $("#CurrentCartDescription").text()
>>> $("#CurrentCartDescription").html(atob(encodedDescription));
>>>
>>> However, when I try to do it for a bunch of fields at once using class
>>> (instead of id), it doesn't work - doesn't touch the values:
>>>
>>> $(".EncodedDescriptionField").html(atob($(".EncodedDescriptionField").text()));
>>>
>>> I am sure I am missing something basic... Greatly appreciate suggestions
>>> -
>>>
>>> On Thursday, May 16, 2019 at 6:54:14 PM UTC-4, Vlad wrote:
>>>>
>>>> I had no clue about it - I mean never heard the terms :)
>>>>
>>>> Thank you very much for point to the direction. After some googling, it
>>>> is almost working.
>>>>
>>>> Encoding is just fine (using btoa).
>>>>
>>>> When I read it back and want to decode - it's not yet behaving right.
>>>> I'm suspecting my javascript is a problem.
>>>>
>>>> There is a bunch of fields which now have encrypted values (class
>>>> 'EncodedDescriptionField'), and I am trying to use the following to
>>>> reclaim
>>>> the original values:
>>>>
>>>>
>>>> $(".EncodedDescriptionField").html(atob($(".EncodedDescriptionField").text()));
>>>>
>>>> What am I doing wrong? (It doesn't change the values - they remain as
>>>> they are, encrypted)
>>>>
>>>> On Thursday, May 16, 2019 at 5:35:39 PM UTC-4, João Matos wrote:
>>>>>
>>>>> Have you considered base64 encoding/decoding?
>>>>>
>>>>> quinta-feira, 16 de Maio de 2019 às 20:43:58 UTC+1, Vlad escreveu:
>>>>>>
>>>>>> I have the following javascript in the view:
>>>>>>
>>>>>> var id = $('#CurrentCartId').text();
>>>>>> var description = $(this).text();
>>>>>> var url='{{=URL('cart','description')}}';
>>>>>> url += '/' + id + '/';
>>>>>> url += description;
>>>>>> ajax(url,[],':eval');
>>>>>>
>>>>>> the reason I use url+= to pass parameters instead of using args in
>>>>>> the URL helper is because the parameters are coming from the html itself
>>>>>> -
>>>>>> they are not known in the controller py.
>>>>>>
>>>>>> now the problem is that it changes the description and I have no way
>>>>>> to recover its original value. for example, when description is "askjdf
>>>>>> d
>>>>>> dka;lskdj 3838&^&%$#@ ((alksjdf__ - ))" (just a randomly typed string
>>>>>> in
>>>>>> this case), it comes out as "askjdf_d___dka_lskdj__3838_____".
>>>>>> Obviously,
>>>>>> it needs to do this conversion in order to pass the parameter, but I
>>>>>> need
>>>>>> to be able to recreate the original string, entered by the user.
>>>>>>
>>>>>> Is there a better way of doing this? I.e. a better way of passing a
>>>>>> parameter in a way that it could be "recreated" and stored in the
>>>>>> database
>>>>>> exactly as typed by the user?
>>>>>>
>>>>>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/web2py/a20934f0-54a3-4bd9-95ff-0d3b60cbcfa1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.