dtsnx44260
dtsnx44260
2015-07-26 14:55

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

For example: Stackoverflow's page

I push F12 in Crome web-browser and in console put next:

var item = document.querySelectorAll('.question-summary');
var outputValue = item.length;
outputValue;

The output I get is 15

Question is can I send this info (the output value) to my myfile.php file (for example get sing in one of my divs There are 15 questions on that particular stackoverflow's page via <? echo 'There are ' . outputValue . ' questions on that particular stackoverflow's page'; ?>), so in future I'll be able to put this information to MySQL database (but for now I just need to print out outputValue on myfile.php )?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • duanaigua4033 duanaigua4033 6年前

    Yes, using a GET request, you could pass the length as a query string parameter -

    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
    }
    
    点赞 评论 复制链接分享

相关推荐