[英]Can I send information from browser console (via AJAX) to my php file on local/remote host?
例如:Stackoverflow的页面
我在Crome网络浏览器中按下F12,然后在控制台中按下:
var item = document.querySelectorAll('.question-summary');
var outputValue = item.length;
outputValue;
我得到的输出是15
问题是我可以将此信息(输出值)发送到myfile.php文件(例如在我的一个div中唱歌) <? echo 'There are ' . outputValue . ' questions on that particular stackoverflow's page'; ?>
通过<? echo 'There are ' . outputValue . ' questions on that particular stackoverflow's page'; ?>
There are 15 questions on that particular stackoverflow's page
<? echo 'There are ' . outputValue . ' questions on that particular stackoverflow's page'; ?>
),所以将来我可以将这些信息放到MySQL数据库中(但是现在我只需要在outputValue
上打印输出值)?
是的,使用GET请求,您可以将长度作为查询字符串参数传递-
xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET", "server.php?question-summaries="+item.length);
xmlhttp.send();
server.php
if (is_numeric($_GET['question-summaries'])) {
// Insert into database
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.