简体   繁体   English

在不同的div中显示表单结果

[英]display form results inside different div

im just wondering how to use javascript (i think it will be javascript but not sure) to have the results of the search action be displayed inside another div, just like sites such as ebay, or even stackoverflow. 即时通讯只是想知道如何使用javascript(我认为会是javascript,但不确定)是否可以将搜索操作的结果显示在另一个div中,就像ebay这样的网站,甚至stackoverflow。 heres a snippet of my html 这是我的html的摘要

<div id="searchsign">
   <div style="width: 65%; float:left;height:100%;">
      <form id="searchdivebay" action="searchdivebay.php" method="get">
         <div class="searchbox"><input type="text" name="searchbox" id="searchboxinput"/></div>
         <div class="searchbtn"><input type ="submit" name="searchbutton" value="Search DiveBay"/></div>
      </form>
   </div>
   <div style="width: 35%; float:right;height:100%;">
      <ul class="signreg">
         <li><i>Existing user?</i> <a href="#">SIGN IN</a></li>
         <li><i>or, New user? </i><a href="#">REGISTER</a></li>
      </ul>
   </div>   
</div>

<div id="main">
   <div style="height:2px; background-color:blue; top: 0px;"></div>
      <div id="showsearch">

      </div>

and yeah, basically i want to have the result of the searchdivebay.php form action be displayed inside the "showsearch" div at the bottom of the code. 是的,基本上,我想让searchdivebay.php表单操作的结果显示在代码底部的“ showsearch” div中。 the script works and i could post the code for that if necessary. 该脚本有效,如有必要,我可以发布该代码。 but to the point, what is the javascript (if any) to have this functionality? 但要点是,具有此功能的javascript(如果有)是什么?

The simplest way is to use an inline frame and refer to it as target in the from. 最简单的方法是使用嵌入式框架,并将其称为from中的目标。 The inline frame can be wrapped inside a div if needed, of course. 当然,如果需要,可以将内联框架包装在div内。 Example: 例:

<form id="searchdivebay" action="searchdivebay.php" method="get"
   target="results">
...
</form>
...
<iframe name="results" width="500" height="200">
</iframe>

It looks like you will want to use some JQuery like below (which will of course require that you actually include the JQuery library): 看来您将要使用以下类似的JQuery(当然,这需要您实际上包含JQuery库):

function fetchData(){
  var url = 'searchdivebay.php';
  // The jQuery way to do an ajax request
  $.ajax({            
    type: "GET",
    url: url,
    data: "", // Your parameters here. looks like you have none
    success: function(html){
      // html contains the literal response from the server
      $("#showsearch").html(html);
    }
  });
}

Hope this helps! 希望这可以帮助!

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

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