我的POST
方法不会显示在网页上,但我的GET
方法即使在我的global.js中没有创建方法。 GET
方法是否附带POST
?我希望我的POST
不显示为GET
。我怎么做?我知道我的POST
工作我认为,因为在网络(即在与控制台的浏览器),POST
方法在那里,预览打印出$_POST
和$_SESSION
。如何让POST
显示在页面上而不是GET
。POST方法不显示,但GET方法确实
Button.php
<!doctype html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"> </script>
<script src ="global.js"></script>
<title>Button POST</title>
</head>
<body>
<button id ="postbutton" onclick="location.href='storage.php'">GO</button><br>
</body>
</html>
storage.php
<?php
print_r($_POST);
if(isset($_POST['json'])){
$_SESSION['object'] = $_POST["json"];
print_r($_SESSION);
echo 'True';
}else {
echo 'False';
}
global.js
var oject = [{name:'John', age:17},{name:'James', age:22}];
var json = JSON.stringify(oject);
$(document).ready(function(){
$('#postbutton').click(function(){
$('#output').html('sending..');
var jobject = JSON.stringify(oject);
console.log(jobject);
$.ajax({
method:'post',
url:'storage.php',
data:{json:oject},
})
.done(function(data){
console.log(data);
});
});
});
好吧,您正在设置window.location ....您无法进行Ajax调用并同时设置位置。你为什么重定向? – epascarello
@epascarello这只是一个例子,我正在做的是将其重定向到其他不是'storage.php'的页面。认为这没有什么区别,但似乎是这样。 – CBegin
那么你需要在Ajax调用完成后重定向。所以把它放在完成的方法中。 – epascarello