Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.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 POST方法不显示,但GET方法显示_Javascript_Php_Ajax_Post - Fatal编程技术网

Javascript POST方法不显示,但GET方法显示

Javascript POST方法不显示,但GET方法显示,javascript,php,ajax,post,Javascript,Php,Ajax,Post,我的POST方法不会显示在网页上,但是我的GET方法会显示,即使我还没有在我的global.js中使用它创建方法。GET方法是否与POST一起提供?我希望我的POST显示notGET。我该怎么做?我知道我的POST是有效的,因为在网络中(即在带有控制台的浏览器中),有POST方法,预览会打印出$\u POST和$\u会话。如何使POST显示在页面上而不是GET Button.php <!doctype html> <html> <head> &

我的
POST
方法不会显示在网页上,但是我的
GET
方法会显示,即使我还没有在我的global.js中使用它创建方法。
GET
方法是否与
POST
一起提供?我希望我的
POST
显示not
GET
。我该怎么做?我知道我的
POST
是有效的,因为在网络中(即在带有控制台的浏览器中),有
POST
方法,预览会打印出
$\u POST
$\u会话
。如何使
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">GO</button><br>
  </body>
</html>

您的GET方法是有效的,因为您使用了onclick with
location.href
方法。这将始终使用GET方法重定向,以便它可以显示您的输出!但要在ajax中使用
POST方法,您需要删除onclick方法并将返回数据附加到body元素

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">GO</button><br>
  </body>
</html>

为什么在同时调用
$.ajax()
的按钮中有一个
onclick

GO


如果要使用
$.ajax()
无需单击
onclick
。您可以调用
location.href
indside
done(函数(数据){})
如果它满足您的条件,并且您希望将用户重定向到其他地方。

您正在设置窗口。location。。。。您不能同时进行Ajax调用和设置位置。为什么要重定向?@epascarello这只是一个例子,我正在做的是将它重定向到另一个不是
storage.php
的页面。我认为这不会有什么不同,但看起来确实如此。在Ajax调用完成后,您需要重定向。所以把它放在done方法中。@epascarello以前试过,但没有成功。displated
Array()False
感谢您的回答:D它现在似乎可以工作了,但是如何将它重定向到其他页面并仍然具有该值?我所做的是将该值存储到
storage.php
中,并将该值用于另一个页面。
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);
    });
  });
});
<!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">GO</button><br>
  </body>
</html>
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){
       $("body").append(data);
    });
  });
});