gpt4 book ai didi

javascript - 如何在php中获取脚本变量值

转载 作者:行者123 更新时间:2023-11-30 00:11:46 25 4
gpt4 key购买 nike

我正在使用弹出窗口根据点击功能的 id 显示消息。所以我想在 php 中打开弹出窗口时获取 id。提前致谢

<p>Link 1</p>
<a data-toggle="modal" data-id="ISBN564541" title="Add this item" class="open-AddBookDialog btn btn-primary" href="#addBookDialog">test</a>

<p>&nbsp;</p>

<div class="modal hide" id="addBookDialog">
<div class="modal-header">
<button class="close" data-dismiss="modal">×</button>
<h3>Modal header</h3>
</div>
<div class="modal-body">
<p>some content</p>
<?php //here i want to getting script variable value for database purpose?>

</div>
</div>

我的脚本是

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

在 ajax 调用中,我从下一页获取 ID,但我想在同一页中获取值

function viwpost(id) { 

var pid=id;

$.ajax({
type: "POST",
url: "view_more.php",
data: "pid=" + pid ,
success: function(data)
{
$("#myModal21").html(data);
}
});
}

最佳答案

因为您已经在使用 jQuery 框架/API:

你可以简单地使用

$.get('phpfile.php' { id: myBookId }).done(function (response) { alert(response); });

您的 PHP 文件可以像这样获取请求:

$_GET['id'];

If you're trying to make a live pop-up to load the data, this is an incorrect method of doing so. PHP script is only loaded once on server running and sending a request will only give you a response so ensure you research.

我建议您创建 PHP 文件来回显要弹出的数据。

将响应发送回请求的 PHP 文件演示(按要求):

if(isset($_GET['id']))
{
echo 'what ever is outputted to the client will be received in the response';
}

关于javascript - 如何在php中获取脚本变量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36178044/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com