1

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?

2 Answers 2

2

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]
Sign up to request clarification or add additional context in comments.

Comments

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

3 Comments

this neither doesn't work :( Mayby I have to use the POST-method for this?
Check out this theme

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.