Html 将 div 设置为 post 方法结果页面的目标容器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5263887/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 07:15:45  来源:igfitidea点击:

set div as target container for result page of a post method

posthtml

提问by zerey

.I have a div tag that is also divided into two divs. here is the code:

.我有一个 div 标签,它也分为两个 div。这是代码:

<div>
<div id="search">
<form id="try" method="post">
Batch: <input id="batch" name="batch" type="text"/>Dept: <input id="dept" name="dept" type="text"><input type="submit"/>
</div>
<div id="receiver">

</div>
</div>

I have placed a search option in the div named "search" using post method. what i want to do is that when i click the submit button the page to receive the values will appear on the div named "receiver".

我使用 post 方法在名为“search”的 div 中放置了一个搜索选项。我想要做的是,当我单击提交按钮时,接收值的页面将出现在名为“接收器”的 div 上。

is this possible? if it is, please help..

这可能吗?如果是,请帮忙。。

回答by Radagast the Brown

The ways you have for this are:

您可以采用的方法是:

1 - The simplest - instead of a div - use an IFrame like this

1 - 最简单的 - 而不是 div - 使用像这样的 IFrame

<div id="search">
  <form id="try" method="post" target="receiver" action="url-to-server-Page">
     Batch: <input id="batch" name="batch" type="text"/>
     Dept: <input id="dept" name="dept" type="text" />    
     <input type="submit"/>
  </form>
  </div>
  <iframe name="receiver" id="receiver"></iframe>
</div>

The disadvantage in this case is that the search-result that come in this case from url-to-server-page- is a complete and independent HTML page that is nested in your search page. It is not effected by styles of the parent page, and the communication between them for JavaScript operations is rather combersome.

这种情况下的缺点是,在这种情况下,来自url-to-server-page的搜索结果是一个完整且独立的 HTML 页面,它嵌套在您的搜索页面中。不受父页面样式的影响,JavaScript操作之间的通信比较繁琐。

2 - with some JavaScript skills you can use AJAX. There are many libraries on the net that can help you do it in very few lines of code. jQuery is the simplest, although it's the one I like least... http://jquery.com/

2 - 具有一些 JavaScript 技能,您可以使用 AJAX。网络上有许多库可以帮助您用很少的代码行来完成。jQuery 是最简单的,虽然它是我最不喜欢的... http://jquery.com/

3 - use a full round-trip

3 - 使用完整的往返

  <div id="search">
    <form id="try" method="post" target="receiver" action="url-to-server-Page">
       Batch: <input id="batch" name="batch" type="text"/>
       Dept: <input id="dept" name="dept" type="text" />    
      <input type="submit"/>
    </form>
    <div id="receiver">
        <?php if (isset($_POST['batch']) && isset($_POST['dept'])){
                  //display search results here.
              }
        ?>
    </div>
 </div>

回答by Isaac Truett

You want what's called "AJAX." There are a number of libraries available, such as Google Web Toolkitor jQueryto accomplish what you want.

您需要所谓的“AJAX”。有许多可用的库(例如Google Web ToolkitjQuery)来完成您想要的操作。

回答by Tim Joyce

Can you clarify? Is this a php page and you are posting to self or are you looking to use ajax to populate the div?

你能澄清一下吗?这是一个 php 页面并且您正在发布给自己还是您想使用 ajax 来填充 div?

If it is php and you post to self then you can simply check if the post has been made inside that div :

如果它是 php 并且您发布给 self ,那么您可以简单地检查该帖子是否已在该 div 内制作:

<div id="receiver">
    <?php if (isset($_POST['batch']) && isset($_POST['dept'])){
              //display search results here.
          }
    ?>
</div>