0

I want to send all my names,values and labels of my form-elements when I klick on a button, I didnt make a submit-button, beause the I got them in a wrong order, so I make this in JavaScript:

$('#mybutton').click(function() {
    m.modal('show'); 

    var all=[];

    $('textarea, select, input').each(function(index){
        var label= $(this).parent().find('label').html();
        var value= $(this).val();
        var name= $(this).attr('name');
        all.push([name,value,label]);           
    })

    $.ajax({
         dataType: "text",
         url: "befund",
         data: {
            wert : all  
         },
         success: function(data){
            $('#mymodal').find('.modal-body').html(data); 
         }
    })
});

in the python server-script (bottle) I try this:

@app.route('/web/befund')
def modalcontent() -> str:
       x = request.query.wert[0][1]  
       print (x)
       return('test')

the problem is that I see in the browser, that the right array is send but when I try to see one element of the array with "request.query.wert[0][1]" I only get a http-error 500 (internerl server error). Can anybody help me please?

nina_berlini
  • 165
  • 1
  • 2
  • 10

2 Answers2

1

You can use POST for this (and should, if this is sensitive data and your connection is secure). However, you need to turn the data into a JSON string, then decode it on the server.

data: {
    wert: JSON.stringify(all)  
},

On the server:

wert = json.loads(request.params.wert);
print wert[0][1]
0

I think the wert it is the object on the server side. Try accesing data by `x=request.query.wert[0]

or x=request.query['wert'][0]

Im not using python now, but it seems like right

Ilya Gudov
  • 1
  • 1
  • 4