将数据发送到模态

Send data to a modal

我正在使用 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}}?

提前致谢

我在这里假设模式从一开始就在同一页面上。您可以将 .... 替换为 {{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!");
  }
});