[英]Is there a way to record a page view when using bootstrap modal
Is there a way to record that a user to my site who click on the "more info" button on a modal is recorded in a database. 有没有一种方法可以记录在我的网站上单击模式上的“更多信息”按钮的用户,该用户记录在数据库中。 What I am trying to do is get an idea of which scholarships the students are most interested in and record that data. 我正在尝试做的是了解学生最感兴趣的奖学金并记录该数据。 The page is produced using MySQL and PHP and bootstrap, so I understand that there is an issue with sending the data back to the server because the page has already been rendered by the server. 该页面是使用MySQL和PHP以及引导程序生成的,因此我知道将数据发送回服务器存在问题,因为该页面已经由服务器呈现。
Here is a screenshot of part of the page. 这是页面一部分的屏幕截图。
I realize that PHP and javascript deal with data in different ways, but I guess my question is how might I accomplish this, or is this even possible using the existing PHP and bootstrap. 我意识到PHP和javascript以不同的方式处理数据,但是我想我的问题是我应该如何实现这一目标,或者甚至可以使用现有的PHP和Bootstrap实现。 My initial thought is to attach an event to the "more info" button but then the page needs to be refreshed to get the data to the server which would be confusing for the students using the site. 我最初的想法是将事件附加到“更多信息”按钮上,但是随后需要刷新页面才能将数据获取到服务器,这会使使用该网站的学生感到困惑。
Any help with how this might be done would be greatly appreciated. 对此方法的任何帮助将不胜感激。
So here is the code that I have so far. 所以这是我到目前为止的代码。
The modal code: (* I didn't include all of it as I don't think it necessary) 模态代码:(*我没有包括所有内容,因为我认为没有必要)
<!-- Trigger the modal with a button -->
<button type="button" onclick="saveData(<? echo $row['id'].",". "1"; ?>)"
**class="btn btn-info btn-lg" id="savedata" data-toggle="modal" data-
target="#myModal<? echo $row['id']; ?>">More Information.</button>**
<!-- Modal -->
<div id="myModal<? echo $row['id']; ?>" class="modal fade" role="dialog">
<div class="modal-dialog">
And here is the Ajax code 这是Ajax代码
<script>
function window.saveData(){
var name=$('#savedata').val();
$.ajax({
type:"post",
url:"includes/post_scholarship_count.php",
data:"nm="+name,
success: function(msg){
alert('Success Insert data');
}
});
}
</script>
When I inspect the page running on the server I get an error 当我检查服务器上运行的页面时,出现错误
Uncaught ReferenceError: saveData is not defined at HTMLButtonElement.onclick (university.php:182) 未被捕获的ReferenceError:在HTMLButtonElement.onclick(university.php:182)上未定义saveData
Which is: 这是:
<button type="button" onclick="saveData(826,1)" class="btn btn-info btn-lg"
id="savedata" data-toggle="modal" data-target="#myModal826">More Information.
</button>
I am guessing that the issue something to do with the modal button but I am not even sure you can do this in such a manner. 我猜想这个问题与模式按钮有关,但我什至不确定您是否可以通过这种方式进行。
Again thanks for looking. 再次感谢您的关注。
Maybe you can use Ajax to do it. 也许您可以使用Ajax来做到这一点。 Create a page or function to receive a post request with php. 创建一个页面或函数以使用php接收发布请求。 And then when you click the button you send a post to this php file 然后,当您单击按钮时,会将帖子发送到此php文件
//ajax script
$.post( "url_to_file.php", { name: value} ).done(function(
//console.log(data);
})
//php script in url_to_file.php
if(isset($_POST['name']){
$value = $_POST['name'];
exit();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.