EDIT I am new to development. So may be I am not getting this simple issue.
This has been marked Duplicate. But I don't think it is. My second Modal lies in a different file. It is not in the same file as the first Modal. So I am not sure how do I refer to the second Modal from the Ajax(jQuery) in the first Model.
ORIGINAL
I have been trying to open a Modal from another Modal. In first Modal I make an Ajax call to verify the code variable. If success I would like Ajax call to redirect the user to the actual signup form. It does redirect but I would like it to open as a Modal not as normal page. Here is Ajax in my first Modal:
$(function() {
$("#verify").click(function () {
var code = $("#code").val();
var csrf = $('input[name="csrfmiddlewaretoken"]').val();
var link = "{% url 'health:add_doctor' %}"
$.ajax({
type: "POST",
url: '/verify_code/',
data: {
'code': code,
'csrfmiddlewaretoken': csrf
},
dataType: 'json',
success: function (data) {
alert(link)
if (data.verified == 1) {
$(location).attr('href', link);
}
}
});
});
});
Second Modal code:
<form action="{% url 'health:add_doctor'%}" method="post" accept-charset="utf-8" class="form" role="form">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="title-doc">Add a Doctor</h4>
</div>
<div class="modal-body">
{% csrf_token %}
<div class="row">
Fields here
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
<button class="btn btn-success" type="submit">Add</button>
</div>
</form>
The second Modal opens fine on a button's click another page on. But I am not getting how to do it from a Modal. I tried few answers on SO but it doesn't work in my case.
Can anyone help, please.