Reputation: 9065
I have a bootstrap modal which holds a form and from holds a select option field and I would like to populate this with help of ajax on modal('show')
So I have been trying the following but on first click won't fire and after each click the request are duplicated
$('#addNew').modal('show');
$('#addNew').on('show.bs.modal', function(e) {
//ajax call to populate select option
var url = ajaxurl + '?action=getCategories';
$.ajax({
type: "POST",
cache: false,
success: function(html) {
}
});
});
Upvotes: 1
Views: 1109
Reputation: 3512
Why not changing the scenario?
function showAddNewModal(){
//ajax call to populate select option
var url = ajaxurl + '?action=getCategories';
$.ajax({
type: "POST",
cache: false,
success: function(html) {
//populate select option here
$('#addNew').modal('show');
}
});
}
Also when you are using POST method , you should change your request to :
$.ajax({
url:ajaxurl,
data:{"action":"getCategories"},
type: "POST",
cache: false,
success: function(html) {
//populate select option here
$('#addNew').modal('show');
}
});
Upvotes: 1