将值从JS传递给PHP

时间:2015-01-17 19:43:06

标签: javascript php jquery

我想将客户端ID从链接传递给像这样的模式

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

我使用像这样的jquery来获取这个id

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

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

问题是如何拾取这本书并使用它来执行查询以使用php获取一些数据

3 个答案:

答案 0 :(得分:1)

使用可以将数据发布到服务器中的php文件

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

http://api.jquery.com/jquery.post/

的更多信息

答案 1 :(得分:0)

你需要对你的php进行ajax调用。您可以阅读非常广泛的文章。

http://www.w3schools.com/jquery/jquery_ajax_intro.asp可以让你开始使用它。

答案 2 :(得分:0)

您可以使用此类代码发送AJAX请求

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

在PHP脚本中,您将从

获取它
$_POST['id']