javascript - 如何从javascript获取变量到php?

标签 javascript php html web

我想从代码值中获取一个变量:

/* Link Skor */
Memory.prototype.cekSkor = function(){
    window.location = "./skor/index.php?value=" + this.numMoves;
}

Memory.prototype._winGame = function() {
    var self = this;
    if (this.options.onGameEnd() === false) {
        this._clearGame();
        this.gameMessages.innerHTML = 
            '<h2 class="mg__onend--heading">Keren!</h2>\
            <p class="mg__onend--message">Kamu memenangkan game ini dalam ' + this.numMoves + ' gerakan.</p>\
            <button id="mg__onend--restart" class="mg__button">Ingin Bermain Lagi?</button>\
            <button id="mg__onend--skor" class="mg__button">Cek Skor?</button>';
        this.game.appendChild(this.gameMessages);
        document.getElementById("mg__onend--restart").addEventListener( "click", function(e) {
            self.resetGame();
        });
        document.getElementById("mg__onend--skor").addEventListener( "click", function(e) {
            self.skor();
        });
    } else {
        // run callback
        this.options.onGameEnd();
    }
}

我想将 ( this.numMoves ) 获取到另一个文件是 index.php

<?php
        $skornya = $_GET['value'];
        echo $skornya;
?>

当我运行网络时。我得到错误 值=未读

enter image description here

我需要做什么来解决这个问题?

最佳答案

没办法。 =).在 PHP 中只能接收 $_GET、$_POST、$_REQUEST 或 $data = json_decode( file_get_contents('php://input') );

如果你想要javascript中的变量可以在PHP中使用。您必须使用 Javascript 中的 XMLHttpRequest 和 jQuery 中的 ajax 将其发布到服务器。希望对你有帮助

关于javascript - 如何从javascript获取变量到php?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46167463/

相关文章:

php - XHTML、PHP、MySQL、IE 和 mdash 字符

javascript - Discord.js 在欢迎时提及玩家

javascript - 前端开发可以使用Python代替Javascript吗?

php - 选择条目值为 1 的列名称

PHP 在 iframe 中打开链接

css - 在我的 html 中找不到我的 css 文件

html - FireFox 不显示 CSS/脚本/图像(真正来自子文件夹的任何内容)基本 HTML 站点,IIS7

javascript - 我如何访问.then函数AngularJS中的响应头

javascript - 理解Vue中的 'this'关键字

php - SQL 根据列优先级过滤重复项