send id to a modal with php or ajax
up vote
0
down vote
favorite
I wanna assign a modal to a button , that shows a warning to the client.
the warning is about : are you sure delete that.
my problem is about send the id to modal with ajax or something else and i am newbe with ajax or javascript so my code is Incomplete
here is my button :
<button title="delete" data-modal="md-just-me" data-id=<?= $row->id_post; ?> class="delete-post"></button>
here is my script (Incomplete):
<script>
$(document).ready(function()
$('.delete-post').click(function()
var btn = $(this);
var id = btn.data('id');
$.ajax(
type:"GET",
url:"",
data :
id : id
,
success: function(msg)
alert( 'ok' ) ;
,
error:function()
alert("failure");
);
);
);
});
</script>
i want the button and modal in same page
and this is my model :
<div class="md-modal md-just-me" id="md-just-me">
<?php $id = $_GET['id'];?>
<div class="md-content">
<h2>warning</h2>
<p>do you want continue? </p>
<p>
<button class="btn btn-danger md-close">close</button>
<a href="<?php base_url(post/delete).$id ?>">yes im suer</button>
</p>
</div>
</div>
</div>
javascript jquery html
add a comment |
up vote
0
down vote
favorite
I wanna assign a modal to a button , that shows a warning to the client.
the warning is about : are you sure delete that.
my problem is about send the id to modal with ajax or something else and i am newbe with ajax or javascript so my code is Incomplete
here is my button :
<button title="delete" data-modal="md-just-me" data-id=<?= $row->id_post; ?> class="delete-post"></button>
here is my script (Incomplete):
<script>
$(document).ready(function()
$('.delete-post').click(function()
var btn = $(this);
var id = btn.data('id');
$.ajax(
type:"GET",
url:"",
data :
id : id
,
success: function(msg)
alert( 'ok' ) ;
,
error:function()
alert("failure");
);
);
);
});
</script>
i want the button and modal in same page
and this is my model :
<div class="md-modal md-just-me" id="md-just-me">
<?php $id = $_GET['id'];?>
<div class="md-content">
<h2>warning</h2>
<p>do you want continue? </p>
<p>
<button class="btn btn-danger md-close">close</button>
<a href="<?php base_url(post/delete).$id ?>">yes im suer</button>
</p>
</div>
</div>
</div>
javascript jquery html
You don't want to use php to show the modal, that would require you to refresh the page for the modal to appear. You want to click them button, show the modal, and then when they confirm the modal, THEN you make an ajax request.
– SpeedOfRound
Nov 9 at 18:51
yes i know about that . but i need id_post for the tag <a> in modal and i dont know how send it
– sajadsholi
Nov 9 at 18:57
and yeah when i click the button the modal is showen up but with no id
– sajadsholi
Nov 9 at 19:00
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I wanna assign a modal to a button , that shows a warning to the client.
the warning is about : are you sure delete that.
my problem is about send the id to modal with ajax or something else and i am newbe with ajax or javascript so my code is Incomplete
here is my button :
<button title="delete" data-modal="md-just-me" data-id=<?= $row->id_post; ?> class="delete-post"></button>
here is my script (Incomplete):
<script>
$(document).ready(function()
$('.delete-post').click(function()
var btn = $(this);
var id = btn.data('id');
$.ajax(
type:"GET",
url:"",
data :
id : id
,
success: function(msg)
alert( 'ok' ) ;
,
error:function()
alert("failure");
);
);
);
});
</script>
i want the button and modal in same page
and this is my model :
<div class="md-modal md-just-me" id="md-just-me">
<?php $id = $_GET['id'];?>
<div class="md-content">
<h2>warning</h2>
<p>do you want continue? </p>
<p>
<button class="btn btn-danger md-close">close</button>
<a href="<?php base_url(post/delete).$id ?>">yes im suer</button>
</p>
</div>
</div>
</div>
javascript jquery html
I wanna assign a modal to a button , that shows a warning to the client.
the warning is about : are you sure delete that.
my problem is about send the id to modal with ajax or something else and i am newbe with ajax or javascript so my code is Incomplete
here is my button :
<button title="delete" data-modal="md-just-me" data-id=<?= $row->id_post; ?> class="delete-post"></button>
here is my script (Incomplete):
<script>
$(document).ready(function()
$('.delete-post').click(function()
var btn = $(this);
var id = btn.data('id');
$.ajax(
type:"GET",
url:"",
data :
id : id
,
success: function(msg)
alert( 'ok' ) ;
,
error:function()
alert("failure");
);
);
);
});
</script>
i want the button and modal in same page
and this is my model :
<div class="md-modal md-just-me" id="md-just-me">
<?php $id = $_GET['id'];?>
<div class="md-content">
<h2>warning</h2>
<p>do you want continue? </p>
<p>
<button class="btn btn-danger md-close">close</button>
<a href="<?php base_url(post/delete).$id ?>">yes im suer</button>
</p>
</div>
</div>
</div>
<script>
$(document).ready(function()
$('.delete-post').click(function()
var btn = $(this);
var id = btn.data('id');
$.ajax(
type:"GET",
url:"",
data :
id : id
,
success: function(msg)
alert( 'ok' ) ;
,
error:function()
alert("failure");
);
);
);
});
</script>
<script>
$(document).ready(function()
$('.delete-post').click(function()
var btn = $(this);
var id = btn.data('id');
$.ajax(
type:"GET",
url:"",
data :
id : id
,
success: function(msg)
alert( 'ok' ) ;
,
error:function()
alert("failure");
);
);
);
});
</script>
<div class="md-modal md-just-me" id="md-just-me">
<?php $id = $_GET['id'];?>
<div class="md-content">
<h2>warning</h2>
<p>do you want continue? </p>
<p>
<button class="btn btn-danger md-close">close</button>
<a href="<?php base_url(post/delete).$id ?>">yes im suer</button>
</p>
</div>
</div>
</div>
<div class="md-modal md-just-me" id="md-just-me">
<?php $id = $_GET['id'];?>
<div class="md-content">
<h2>warning</h2>
<p>do you want continue? </p>
<p>
<button class="btn btn-danger md-close">close</button>
<a href="<?php base_url(post/delete).$id ?>">yes im suer</button>
</p>
</div>
</div>
</div>
javascript jquery html
javascript jquery html
asked Nov 9 at 18:45
sajadsholi
31
31
You don't want to use php to show the modal, that would require you to refresh the page for the modal to appear. You want to click them button, show the modal, and then when they confirm the modal, THEN you make an ajax request.
– SpeedOfRound
Nov 9 at 18:51
yes i know about that . but i need id_post for the tag <a> in modal and i dont know how send it
– sajadsholi
Nov 9 at 18:57
and yeah when i click the button the modal is showen up but with no id
– sajadsholi
Nov 9 at 19:00
add a comment |
You don't want to use php to show the modal, that would require you to refresh the page for the modal to appear. You want to click them button, show the modal, and then when they confirm the modal, THEN you make an ajax request.
– SpeedOfRound
Nov 9 at 18:51
yes i know about that . but i need id_post for the tag <a> in modal and i dont know how send it
– sajadsholi
Nov 9 at 18:57
and yeah when i click the button the modal is showen up but with no id
– sajadsholi
Nov 9 at 19:00
You don't want to use php to show the modal, that would require you to refresh the page for the modal to appear. You want to click them button, show the modal, and then when they confirm the modal, THEN you make an ajax request.
– SpeedOfRound
Nov 9 at 18:51
You don't want to use php to show the modal, that would require you to refresh the page for the modal to appear. You want to click them button, show the modal, and then when they confirm the modal, THEN you make an ajax request.
– SpeedOfRound
Nov 9 at 18:51
yes i know about that . but i need id_post for the tag <a> in modal and i dont know how send it
– sajadsholi
Nov 9 at 18:57
yes i know about that . but i need id_post for the tag <a> in modal and i dont know how send it
– sajadsholi
Nov 9 at 18:57
and yeah when i click the button the modal is showen up but with no id
– sajadsholi
Nov 9 at 19:00
and yeah when i click the button the modal is showen up but with no id
– sajadsholi
Nov 9 at 19:00
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
Ok, I've whipped up an example here.
Basically, I grab the id of the item that calls the modal, and set an attribute in the modal so that it can be accessed from the confirmation button:
var modalid = $(this).closest('.modal').data('id')
add a comment |
up vote
0
down vote
There is a excellent library called SweetAlert that can ease this process for you. First, you need to add the library.
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
Now, if you want a confirmation message, all you got do is add the following code.
$('.delete-post').click(function()
swal(
title: 'Warning!',
text: "Do you want continue?",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
cancelButtonText:"No",
confirmButtonText: 'Yes, I am sure!'
).then((result) =>
// If true, then call your `ajax` here.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Ok, I've whipped up an example here.
Basically, I grab the id of the item that calls the modal, and set an attribute in the modal so that it can be accessed from the confirmation button:
var modalid = $(this).closest('.modal').data('id')
add a comment |
up vote
0
down vote
Ok, I've whipped up an example here.
Basically, I grab the id of the item that calls the modal, and set an attribute in the modal so that it can be accessed from the confirmation button:
var modalid = $(this).closest('.modal').data('id')
add a comment |
up vote
0
down vote
up vote
0
down vote
Ok, I've whipped up an example here.
Basically, I grab the id of the item that calls the modal, and set an attribute in the modal so that it can be accessed from the confirmation button:
var modalid = $(this).closest('.modal').data('id')
Ok, I've whipped up an example here.
Basically, I grab the id of the item that calls the modal, and set an attribute in the modal so that it can be accessed from the confirmation button:
var modalid = $(this).closest('.modal').data('id')
answered Nov 9 at 19:14
SpeedOfRound
434211
434211
add a comment |
add a comment |
up vote
0
down vote
There is a excellent library called SweetAlert that can ease this process for you. First, you need to add the library.
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
Now, if you want a confirmation message, all you got do is add the following code.
$('.delete-post').click(function()
swal(
title: 'Warning!',
text: "Do you want continue?",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
cancelButtonText:"No",
confirmButtonText: 'Yes, I am sure!'
).then((result) =>
// If true, then call your `ajax` here.
add a comment |
up vote
0
down vote
There is a excellent library called SweetAlert that can ease this process for you. First, you need to add the library.
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
Now, if you want a confirmation message, all you got do is add the following code.
$('.delete-post').click(function()
swal(
title: 'Warning!',
text: "Do you want continue?",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
cancelButtonText:"No",
confirmButtonText: 'Yes, I am sure!'
).then((result) =>
// If true, then call your `ajax` here.
add a comment |
up vote
0
down vote
up vote
0
down vote
There is a excellent library called SweetAlert that can ease this process for you. First, you need to add the library.
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
Now, if you want a confirmation message, all you got do is add the following code.
$('.delete-post').click(function()
swal(
title: 'Warning!',
text: "Do you want continue?",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
cancelButtonText:"No",
confirmButtonText: 'Yes, I am sure!'
).then((result) =>
// If true, then call your `ajax` here.
There is a excellent library called SweetAlert that can ease this process for you. First, you need to add the library.
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
Now, if you want a confirmation message, all you got do is add the following code.
$('.delete-post').click(function()
swal(
title: 'Warning!',
text: "Do you want continue?",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
cancelButtonText:"No",
confirmButtonText: 'Yes, I am sure!'
).then((result) =>
// If true, then call your `ajax` here.
answered Nov 9 at 19:51
Alain Cruz
1,5231818
1,5231818
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53231653%2fsend-id-to-a-modal-with-php-or-ajax%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You don't want to use php to show the modal, that would require you to refresh the page for the modal to appear. You want to click them button, show the modal, and then when they confirm the modal, THEN you make an ajax request.
– SpeedOfRound
Nov 9 at 18:51
yes i know about that . but i need id_post for the tag <a> in modal and i dont know how send it
– sajadsholi
Nov 9 at 18:57
and yeah when i click the button the modal is showen up but with no id
– sajadsholi
Nov 9 at 19:00