2016-11-22 33 views
0

我想發送我所有的表單元素的名稱,值和標籤,當我點擊一個按鈕時,我沒有提交提交按鈕,因爲我得到了他們在一個錯誤的順序,所以我使這個在JavaScript:每個Ajax發送一個數組到一個python-server-script

$('#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); 
     } 
    }) 
}); 
在Python服務器腳本(瓶)我試試這個

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

的問題是,我在瀏覽器中看到,發送正確的數組,但是當我嘗試用「request.query.wert [0] [1]」查看數組的一個元素時「我只得到一個http錯誤500(internerl se rver錯誤)。有人可以幫我嗎?

回答

0

我認爲wert是服務器端的對象。嘗試通過`X = request.query.wert [0]

或 X = request.query [ 'WERT'] accesing數據[0]

Im不使用python現在,但它似乎是正確的

+0

這既沒有工作:(Mayby我都用這個的POST方法 –

+0

看看這個主題 –

+0

http://stackoverflow.com /問題/ 464040 /如何,都-後和獲取變量,處理功能於蟒蛇 –

0

您可以使用POST(如果這是敏感數據並且連接安全)。 但是,您需要將數據轉換爲JSON字符串,然後在服務器上對其進行解碼。

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

在服務器上:?

wert = json.loads(request.params.wert); 
print wert[0][1] 
相關問題