php代码在本地工作,但不能在服务器上工作

时间:2020-11-08 20:31:04

标签: php html

我的HTML代码:

<html>
    <head>
        <title>itp4</title></head>
    <body>
        <!--src for external script file-->
        <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>

        <!--AJAX Js used here: -->
        <script type="text/javascript">

        $("document").ready(function(){ //detacting the document is ready to be exceuted

            $(".js-ajax-php-json").submit(function(){ //when submit button is clicked
                var data = {"action": "test" }; //php case, line 12
                data = $(this).serialize() + "&" + $.param(data); //serialize the value to pass

                $.ajax({ //perform an AJAX request
                    type: "POST", //define the type to Post
                    dataType: "json", //define the data output type to be json
                    url: "https://infocpst.luddy.indiana.edu/magic-number/generate",  //define the URL for AJAX request
                    data: data, //define the data used to data that mentioned on line 14.

                    success: function(data) { //if above successful
                        $(".return").html( //display the final output on the page.
                            '{"status":' + data["status"] + ',"message":' + data["message"] + "}" +"<br/>" //final output.
                        );
                    }
                });

            return false; //if not success in any step, return false.
            });
        });
        
        </script> <!--AJAX Js usage ends here -->

        <!--Form with all the input data: -->
        <form method="post" action="itp4.php" class="js-ajax-php-json"> 

            <!--I restrict the input to be positive whole numbers only -->
            <input type="number" name="number" min ="0" step="1" oninput="validity.valid||(value='');" placeholder="Number" />

            <!--The team input is set already -->
            <input type="number" name="team" value=63 placeholder="team" /> <br>

            <!--Create the Translate button -->
            <input type="submit" name="submit" value="Translate" />

        </form>

        <!--For the return statement: -->
        <div class="return"></div>

    </body>

</html>

还有我的PHP代码:

<?php
    if (is_ajax()) { //call the function defined below to check the request

        if (isset($_POST["action"]) && !empty($_POST["action"])) { $action = $_POST["action"];} //Checks if action value exists
    }

    //Function to check if the request is an AJAX request, using the AJAX request with isset() to determine if it is decalred or NULL. 
    function is_ajax() {return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';}
?>

我正在根据作业说明构建一个幻数发生器。一切都在本地工作。但是,当我将文件传输到服务器时,按下按钮后,页面会将我重定向到空白页面。

我想知道这是什么问题。我已经检查了许可,没有问题。我使用的Mac系统的php版本为7.0+,服务器为5.0+。 是否由于版本冲突而发出问题?任何帮助将不胜感激!

0 个答案:

没有答案