i am using foundation reveal model but i am not able to pass dynamic url to data-ajax-url
.
i want to pass dynamic project_site.id
in url but not i am able to append dynamic url .
currently i test on local url: "http://0.0.0.0:3000/project_sites/21/attendances/"
here 21 is hard coded url i want to pass dynamic url.
reference i used:- https://codepen.io/sujayjaju/pen/akAYzP?editors=1010
here is my code-
<div class="full reveal" id="exampleModal1" data-reveal data-ajax-url="http://0.0.0.0:3000/project_sites/21/attendances/">
<button class="close-button" data-close aria-label="Close modal" type="button">
<span aria-hidden="true">×</span>
</button>
</div>
<p><button class="button small warning button-margin-top fi-eye" data-open="exampleModal1"> View</button></p>
application.js
$(document).on('open.zf.reveal', "#exampleModal1", function (e) {
var $modal = $(this);
var ajax_url = $modal.data("ajax-url");
if (ajax_url) {
$modal.html("Now Loading: "+ajax_url);
$.ajax(ajax_url).done(function (response) {
$modal.html(response);
});
}
});
2
Answers
If you want to pass a dynamic URL, why don’t you just pass it in jquery instead of relying on data-attributes?
If you must work with
data-attributes
what about doing something like this:Obviously, you would need to replace my
project_site_id
variable with yourproject_site.id
variable.