-1

I want to pass the Client ID from a link to a modal like this

<a id="start" data-toggle="modal" href="#static"  onclick="start();" data-book-id="<?=$id_cl?>">

and i pickup this id using jquery like this

<script type="text/javascript">
    $('#static').on('show.bs.modal', function(e) {

    var bookId = $(e.relatedTarget).data('book-id');
});
</script>

the probleme is how to pickup this bookId and use it to excute query to fetch some data using php

EMIN
  • 737
  • 1
  • 6
  • 9
  • possible duplicate of [How to pass JavaScript variables to PHP?](http://stackoverflow.com/questions/1917576/how-to-pass-javascript-variables-to-php) – JJJ Jan 17 '15 at 19:45
  • That code probably needs to be wrapped in a document ready function `$(function(){ /* code here */ });` – Mottie Jan 17 '15 at 20:08

3 Answers3

1

Use can post data to a php file in your server

<script type="text/javascript">
   $('#static').on('show.bs.modal', function(e) {
   var bookId = $(e.relatedTarget).data('book-id');
   $.post( "queryBookID.php", { bookID: bookId }));
});
</script>

More info at http://api.jquery.com/jquery.post/

George K.
  • 41
  • 2
0

You need to make an ajax call to your php. There are very extensive articles you can read up on.

http://www.w3schools.com/jquery/jquery_ajax_intro.asp could get you started on it.

Ozan
  • 3,709
  • 2
  • 18
  • 23
0

You can use such code for sending AJAX request

<script type="text/javascript">
    $('#static').on('show.bs.modal', function(e) {
        var bookId = $(e.relatedTarget).data('book-id');

        $.post( "/url.php", {id : bookId} function( data ) {
            //handling response here
        });
    });
</script>

and in PHP script you will get it from

$_POST['id']
user995045
  • 25
  • 3