简体   繁体   English

使用引导程序模式时是否可以记录页面浏览量

[英]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.

相关问题 使用 Partial View、JQuery 和 Bootstrap Modal 编辑记录 - Edit Record using Partial View, JQuery and Bootstrap Modal 打开Twitter Bootstrap模态时,如何更改查看后面页面的方式? - How can I change the way I see the page behind when I open a Twitter Bootstrap modal? 单击链接时无法将记录填充到引导模式 - Cannot populate record to bootstrap modal when a link is clicked 关闭 Bootstrap 模式对话框后,查看页面被锁定/禁用 - View page is locked/disabled after closing Bootstrap modal dialog 使用Angular-bootstrap模式和窗口位置时,如何防止页面滚动到顶部:已修复ipad的解决方法? - How to prevent page scroll to top when using Angular-bootstrap modal and window position:fixed workaround for ipad? 当从表中未选择任何记录时,如何在按钮上放置模式。 我正在使用bootstrap 4 - How can I place a modal on a button when no record is selected from my table. I am using bootstrap 4 在调整移动设备页面大小时,Bootstrap模式会向下移动页面 - Bootstrap modal moves down the page when resizing the page for mobile 与Bootstrap 3一起使用时表单输入超调模式 - Form inputs overshoot modal when using with Bootstrap 3 KnockoutJS / Bootstrap-使用javascript关闭模态时清除模态表单 - KnockoutJS/Bootstrap - Clearing modal form when closing modal using javascript 使用Modal的Bootstrap在使用bundleconfig时在何处放置jquery和bootstrap - Bootstrap using Modal where to place jquery and bootstrap when using bundleconfig
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM