我可以从浏览器控制台(通过AJAX)发送信息到我的php文件在本地/远程主机


Can I send information from browser console (via AJAX) to my php file on local/remote host?

例如:Stackoverflow的页面

我按下F12在Crome网页浏览器和在控制台放下:

var item = document.querySelectorAll('.question-summary');
var outputValue = item.length;
outputValue;
我得到的输出是15

问题是我可以将此信息(输出值)发送到我的myfile.php文件(例如通过<? echo 'There are ' . outputValue . ' questions on that particular stackoverflow's page'; ?>在我的divs There are 15 questions on that particular stackoverflow's page中获得sing),所以将来我将能够将此信息放入MySQL数据库(但现在我只需要在myfile.php上打印出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
}