2016-09-29 77 views
0

我正在使用Django,我試圖發送模式中的數據來獲取元素的信息。發送數據到模態

我的按鈕,打開模式是:

<button type="button" class="btn btn-danger" data-toggle="modal" data-target="#informations"> 
    <span class="glyphicon glyphicon-trash" aria-hidden="true">{{registration_id}}</span> 
</button> 

和模態是

<div class="modal fade" tabindex="-1" role="dialog" id="information"> 
    <div class="modal-dialog" role="document"> 
     <div class="modal-content"> 
      <div class="modal-body"> 
       <form method="post" action="{% url 'informations_choices' %}"> 
        {% csrf_token %} 
        <input type="hidden" name="registration" value=......> 
        Get info about : ...... 
       </form> 
      </div> 
      <div class="modal-footer"> 
       <button type="button" class="btn btn-primary" onclick="$('#information').modal('hide');$('#informations_choices').submit()"> 
        Get Info 
       </button> 
      </div> 
     </div> 
    </div> 
</div> 

模態正常打開,但是如何改變「......」到價值(通過與爲例{{registration_id}}存在於按鈕?提前

感謝

回答

0

我是在這裏假設模態從一開始就在同一頁面上。您可以用{{registration_id}}替換....。如果您想讓....處於動態狀態並隨時更改該人在該頁面上,則可能需要查看JavaScript框架並使用AJAX請求。

如果你想要去的純AJAX你最終將像這樣的東西:

$.ajax({ 
    type: "POST", 
    url: "/getnewvalue/", 
    data: { array : items_array }, 
    success: function (data) {  
    // make the changes to the DOM. 
    }, 
    error: function(data) { 
     $("#MESSAGE-DIV").html("Something went wrong!"); 
    } 
}); 
+0

哦,它是如此簡單....爲什麼我不認爲這件事^^」 – Meojifo