简体   繁体   English

如何在PHP变量中传递jQuery变量数据

[英]How to pass jquery variable data in php variable

i having that script from this script i got one id in following text box but i want that in php variable to pass this query "$sub_desti_id" is available in that text box i using this on pop up box to fetch the data thats why i dont want to submit the page .please help me in this case 我从该脚本中获取了该脚本,但在下面的文本框中有一个id,但我希望在php变量中传递该查询“ $ sub_desti_id”在该文本框中可用,我使用此弹出框来提取数据,这就是为什么我不想提交页面。在这种情况下请帮助我

$small_hotel="SELECT * FROM small_add WHERE sub_dest='$sub_desti_id' ";


<input type="hidden" id="bookId" name="bookId" >

 <script>
        $(document).on("click", ".open-AddBookDialog", function () {
         var myBookId = $(this).data('id');
         $(".modal-body #bookId").val( myBookId );
        $('#small_add').modal('show');
        });
        </script>

There is no way to pass variables between PHP and JQuery. 无法在PHP和JQuery之间传递变量。

But you can try something like this, it's not the best, but can set you on the right way. 但是您可以尝试类似的方法,这不是最好的方法,但是可以使您以正确的方式进行操作。 Get your data using PHP and place it in a DOM element like an input or div. 使用PHP获取数据并将其放置在DOM元素(例如input或div)中。 Then access this DOM Element using Jquery 然后使用Jquery访问此DOM元素

// Variable tha recieve the data
<?php $var = "Data"; ?>

// Placing the data in DOM
<input type='text' id='data' value='<?php echo $var ?>'>

// Retrieving using JQuery
<script>
    var data = document.getElementById('data').value;
    alert(data);
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM