0

I'm trying to store td value in array for passing it in POST method for another page. I got this result, but when I pass to my controller to render the view, when I retrieve this array, the words are splitting.

var arrayObj = [];  
 $("table tbody tr input:checkbox:checked").each(function(){
    $(this).parents("tr").find("td").each(function(){
        var text = $(this).text();
        arrayObj.push(text);                
    });
 });

HTML:

<table class="table table-responsive" id="osTable" width="100%" cellspacing="0" align="center">
    <thead align="center">
        <tr>
         <th>#</th>         
         <th>Id OS</th>         
         <th>Name</th>                                          
        </tr>
    </thead>
    <tbody>
     {%for os in ord%}
     <tr>
       <td><input type="checkbox" name="{{os[0]}}"></td>
       <td>{{os[0]}}</td>
       <td>{{os[1]}}</td>
     {%endfor%}
    </tbody>        
</table>

Console log:

(3) ["", "66626", "ROMEU"]
0: ""
1: "66626"
2: "ROMEU"

Passing to controller and catching in the other side, when I print this array,

6 6 6 2 6 R O M E U

Using Flask in the nutshel:

  if request.method == "POST":
    data = request.form['arrayObj']
    return render_template('anotherpage.html',datas=data);

I'm using this function to send to another page JavaScript post request like a form submit

var url = "{{url_for('ordemservico.bloco')}}";
    post_to_url(url,{'data':arrayObj}, "post");
Hasunohana
  • 565
  • 8
  • 22
  • Just reading your logic, it looks like it's going to grab the text from the tds, and push it to the array. It's not clear here how this logic relates to your issue. – Taplar Jun 03 '19 at 21:51
  • Can you post a sample `` or ``, the results you get where the "words are splitting", and an example of the results you expect? It might also be useful to see the code to render the view.
    – OXiGEN Jun 03 '19 at 21:52
  • I will update my question with the outputs and the table – Hasunohana Jun 03 '19 at 21:56
  • 1
    The array is fine, so the problem must be with how you're sending it to the controller, or how the controller is processing the array. – Barmar Jun 03 '19 at 22:05
  • Well, when you use `.push()`, it creates a new element inside the array. So, just use `arrayObj[index] = arrayObj[index] + text` or something similar – Rojo Jun 03 '19 at 22:20
  • @Rojo That does still not work. At least, testing it on JS (View Page) When I iterate the array, the words does not spacing each other. I'm still looking for a solution – Hasunohana Jun 04 '19 at 16:32
  • I do not know if this is normal, but when the array get in controller, it becomes an unicode type, so that's not possible iterate like array... – Hasunohana Jun 04 '19 at 16:49

0 Answers0