简体   繁体   English

提交表单本身而不刷新页面,提交后隐藏/显示div

[英]submit form to itself without page refresh and hide/show the div after submit

is it possible to submit form without refresh and hide the current div, show the div which is hidden. 是否可以提交表单而不刷新并隐藏当前的div,显示隐藏的div。

I tried using following code which submits a form and reloads page. 我尝试使用以下代码提交表单并重新加载页面。

<form method="post" name="searchfrm" action="schedule.php" >
      <div><input type="text" placeholder="Patient Lastname" class="pName" id="pName" name="pName" /></div></br>
      <div><input type="text" placeholder="Surgeon Name" class="sName" id="sName" name="sName" /></div></br>
       <div>
          <span><input type="text" placeholder="mm" class="mm" name="mm" /></span>
          <span><input type="text" placeholder="dd" class="dd" name="dd" /></span>
          <span><input type="text" placeholder="yyyy" class="yyyy" name="yyyy" /></span>
          <span><input type="button" class="sButton" id="sButton"/></span>
      </div>

 <!-- Search Results -->
<div id="searchDiv" class="searchDiv" style="display:none;">
<?PHP
$dateVal = $_POST["yyyy"]-$_POST["mm"]-$_POST["dd"];
$sName = $_POST["sName"];
$pName = $_POST["pName"];
echo "dateVal".$sName;
 $ser_val=@mysql_query("SELECT * FROM issio_patient_procedures WHERE procedure_date='$dateVal' AND asc_id='$ascId' AND surgeon_name='".$sName."' ");
  if(@mysql_num_rows($ser_val)>0)
    {
        $se_count=0;
        while($se_count_det=@mysql_fetch_assoc($ser_val))
        {
            $se_count++;
            echo $se_count_det["surgeon_name"];
        }
    }
?>
</div>
 <!-- Search Results End -->

<div class="scroll" id="scroll" style="display:block;">
   <div class="dateHeader">
      Some content....
   </div
</div

A very popular and common answer is you need an Ajax Request to do such an asynchronous task. 一个非常普遍的常见答案是您需要Ajax Request来执行这样的异步任务。

I can suggest you the jQuery method 我可以建议您使用jQuery方法

       $.ajax({
 url:'dataProcessingPage.php',  
     data: { pName:$("#pName").value, sName:$("#sName").value, .....},
     type:'POST',
     contentType: 'application/json; charset=utf-8', 
     dataType: 'json',  
 success:function(){

      $("#formDiv").hide(); 
       },

});

The above will submit your form to dataProcessingPage.php 以上将您的表单提交到dataProcessingPage.php

Look into Javascript and AJAX w/PHP. 查看带有PHP的Javascript和AJAX。 I'm not going to write all that code out for you, but this should get you in the right direction. 我不会为您编写所有这些代码,但这应该使您朝着正确的方向发展。

Think of "AJAX" as loading fragments of pages or even just data strings for interpretation with Javascript, and refreshing only certain elements on the already loaded DOM. 可以将“ AJAX”视为加载页面片段,甚至只是数据字符串以用Javascript解释,并仅刷新已加载的DOM上的某些元素。 This is the theory, now you have to apply it to what you're doing. 这是理论,现在您必须将其应用于您正在做的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM