Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/432.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AJAX和GET[]困境_Javascript_Php_Ajax - Fatal编程技术网

Javascript AJAX和GET[]困境

Javascript AJAX和GET[]困境,javascript,php,ajax,Javascript,Php,Ajax,我在我的页面上使用PHP模板,通过创建GET变量生成一个包含文件。我在博客页面上有一个评论系统,它在提交时发送一个AJAX GET请求。但是,当用户单击submit时,所有变量都会转到url,我的php模板脚本无法识别它,为了安全起见,只会重定向回主页。我如何避免这种情况 AJAX代码: 模板代码: $_GET[第页];你确定吗?我没有看到带有名称页的变量,我认为您打算使用postID,对吗?使用GET-to-post评论太可怕了。使用-猜猜看-帖子!你能改变blog.php使它使用$\u PO

我在我的页面上使用PHP模板,通过创建GET变量生成一个包含文件。我在博客页面上有一个评论系统,它在提交时发送一个AJAX GET请求。但是,当用户单击submit时,所有变量都会转到url,我的php模板脚本无法识别它,为了安全起见,只会重定向回主页。我如何避免这种情况

AJAX代码:

模板代码:


$_GET[第页];你确定吗?我没有看到带有名称页的变量,我认为您打算使用postID,对吗?使用GET-to-post评论太可怕了。使用-猜猜看-帖子!你能改变blog.php使它使用$\u POST或$\u REQUEST吗;作为脚本中的最后一个语句。您可以尝试在commentpost.php中添加page=4吗?…即使使用return false和POST请求xmlhttp.openPOST,commentpost.php,true,页面仍会返回主页;xmlhttp.setRequestHeaderContent类型,application/x-www-form-urlencoded;xmlhttp.sendpage=4&comment=+comment+&postID=+id;返回false;
<script>
        function postComment() {
            if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp = new XMLHttpRequest();
            }


            else {// code for IE6, IE5

                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    document.getElementById("commentHint").innerHTML = xmlhttp.responseText;
                }
            }
            var comment = document.getElementById("commenter").value;
            var id = document.getElementById("postID").value;
            xmlhttp.open("GET", "commentpost.php?comment=" + comment + "&postID=" + id, true);
            xmlhttp.send();

        }
        setTimeout("postComment()", 1000);

    </script>
    <form>
        <div id="comment">
            <textarea name="comment" id="commenter" rows="4" cols="125" style="max-width: 950px; max-height: 140px;" placeholder="<?php echo $_SESSION["name"] ?>, Write Your Comment Here" class="form-control"></textarea><br>
            <div id="commentHint"></div>
            <input type="submit" onclick="postComment()" value="Submit Comment"  class="btn btn-success btn-sm ">
            <input type="hidden" value="<?php echo $post_id ?>" id="postID">

        </div>
    </form>
               $p = $_GET["page"];
                if (preg_match("</^[a-zA-Z ]*$/>", $p)) {
                    session_start();
                    session_destroy();
                    header("location: index.php?error=2");
                } else {

                    switch ($p) {
                        case "2";
                            include("about.php");
                            break;
                        case "3";
                            include("games.php"); //CREATE PAGES
                            break;
                        case "4";
                            include("blog.php"); <== THIS PAGE IS THE BLOG PAGE
                            break;
                        case "5";
                            include("info.php");
                            break;
                        case "6";
                            include("settings.php");
                            break;
                        case "7";
                            include("functiontest.php");
                            break;
                        case "8";
                            include("styletech.php");
                            break;
                        case "9";
                            include("userlist.php");
                            break;
                        case "10";
                            include("adminpanel.php");
                            break;
                        case "11";
                            include("StyleTuts/styletech.php");
                            break;
                        default:
                            include("home.php");
                            break;
                    }
                }