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>












share|improve this question





















  • 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














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>












share|improve this question





















  • 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












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>












share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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
















  • 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












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')





share|improve this answer



























    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.







    share|improve this answer




















      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













       

      draft saved


      draft discarded


















      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

























      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')





      share|improve this answer
























        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')





        share|improve this answer






















          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')





          share|improve this answer












          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')






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 9 at 19:14









          SpeedOfRound

          434211




          434211






















              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.







              share|improve this answer
























                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.







                share|improve this answer






















                  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.







                  share|improve this answer












                  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.








                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 9 at 19:51









                  Alain Cruz

                  1,5231818




                  1,5231818



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

                      Syphilis

                      Darth Vader #20