jquery将post值发送到另一个页面并加载到当前页面.显示更多,显示更多按钮


jquery send post value to another page and load in current page. Show more, display more button

如果我打扰了别人,我很抱歉。下面的jquery代码假设将网页加载到当前网页中,例如当您点击loadmore/showmoreresults时。我试图加载到当前页面的页面是littlebitego3.php。我可以将输入值从当前页面发送到littlebiteo3.php并加载littlebiteco3.php,但页面在当前页面中加载,而littlebitega3.php页面没有接收到输入值,尽管在jquery代码创建的弹出窗口中,我可以看到带有该值的页面littlebitego3.php,但它加载了一个页面由于加载中的值不知何故不会更新,因此为空。所以我的问题是我应该把代码放在哪里$("#div1").load("littlebitego3.php");因为到目前为止,它放错了地方,没有放在正确的位置。我需要用加载代码配置post代码,但不知道如何做到

   <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4   /jquery.min.js"></script>
   <script>
       $(document).ready(function(){
           $("button").click(function(){
               $("#div1").load("littlebitego3.php");
               $.post("littlebitego3.php",     
                  {
                    name:  $("#test").val(),
                    city: "Duckburg"
                  },
                  function(data,status){
                     alert("Data: " + data + "'nStatus: " + status);
                  }  
               );
          });
     });
 </script>

 <div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div>
 <button>Get External Content</button>
 <p>Name: <input type="text" id="test" value="3"></p>
 <button>Show Value</button>

以下是页面littlebitgo3.php的代码

 $name2 = $_POST['name'];
 echo  $name2;
 }
 ?>

工作在以下的UPDATE编码

   <script>
   $(document).ready(function(){
    $("button").click(function(){
    $("#div1").load("littlebitego3.php",{
  name:  $("#test").val(),
  city: "Duckburg"
    });

    });
  });
 </script>

根据Jeff的说法,我建议您修改littlebitego3.php以响应不同的请求

  • .load发出GET请求
  • $.post发出POST请求

您可以使用$_SERVER['REQUEST_METHOD']来知道是否使用了GET或POST,并做出相应的响应。

GET应使用HTML进行响应POST应使用更新视图所需的任何数据进行响应

阅读.load()文档看起来可以向对象提供请求,所以实际上是在发出POST请求,然后加载它。

$("#div1").load("littlebitego3.php",{
  name:  $("#test").val(),
  city: "Duckburg"
});

不能真正测试它,但我想这样的东西可以工作。