Reputation: 25
how can i call a modal inside a js function without clicking on modal button?
if (email != "") {
$.ajax({
type: "POST",
url: "ajax/email.php",
data: 'email='+ email,
cache: false,
success: function(result){
//alert(result);
if (result == 'true') {
$.ajax({
//do some thing
});
}
else {
$("#sendemail").modal('show');
// there is no button for modal
return false ;
}
}
});
}
now in else case modal is not opening which is in another file.
Upvotes: 0
Views: 192
Reputation: 15616
You forgot to close your success function with a curly brace.
if (email != "") {
$.ajax({
type: "POST",
url: "ajax/email.php",
data: 'email='+ email,
cache: false,
success: function(result){
//alert(result);
if (result == 'true') {
$.ajax({
//do some thing
});
}
else {
$("#sendemail").modal('show');
return false ;
}
} // no syntex error
});
}
Upvotes: 1
Reputation: 47
I would use Jquery Trigger function, this helps to create custom evenHandler. Ideally in your case you can generate an event based on your email status by invoking a function that sends a click event to a object or an id containing modal. For references see examples on Jquery: trigger
Upvotes: 0