My HTML code:
<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>
And my PHP code:
<?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';}
?>
I'm building a magic number generator based on the homework instruction. Everything works locally. But when I transfer the files to the server, after I pressed the button, the page redirects me to a blank page.
I wonder what is the problem with it. I have checked through the permission and there's no problem with it. I'm using a mac system that the php version is 7.0+ and the server is 5.0+. Is the problem issued because of the version conflicts? Any help would be greatly appreciated!