添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
咆哮的牛肉面  ·  SignalR Hub 在 .NET ...·  3 周前    · 
孤独的钢笔  ·  jQuery ...·  2 周前    · 
还单身的松球  ·  jquery ...·  2 周前    · 
完美的抽屉  ·  jquery ...·  2 周前    · 
谈吐大方的毛衣  ·  markdown-image | ...·  2 周前    · 
仗义的刺猬  ·  Dashboard filter not ...·  8 月前    · 
谦逊的开心果  ·  文史 | ...·  9 月前    · 
有胆有识的槟榔  ·  python ...·  9 月前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

How can I refresh just part of the page ("DIV") after my application releases a submit? I'm use JQuery with plugin ajaxForm. I set my target with "divResult", but the page repeat your content inside the "divResult". Sources:

   <script>      
       $(document).ready(function() {      
           $("#formSearch").submit(function() {      
                var options = {    
                  target:"#divResult",
                  url: "http://localhost:8081/sniper/estabelecimento/pesquisar.action"  
               $(this).ajaxSubmit(options);      
               return false;      
   </script>
 <s:form id="formSearch" theme="simple" class="formulario" method="POST">      
 <input id="btTest" type="submit" value="test" >      
                 <div id="divResult" class="quadro_conteudo" >      
                     <table id="tableResult" class="tablesorter">      
                         <thead>      
                                 <th style="text-align:center;">      
                                     <input id="checkTodos" type="checkbox" title="Marca/Desmarcar todos" />      
                                 <th scope="col">Name</th>      
                                 <th scope="col">Phone</th>      
                         </thead>      
                         <tbody>      
                             <s:iterator value="entityList">      
                                 <s:url id="urlEditar" action="editar"><s:param name="id" value="%{id}"/></s:url>      
                                    <td style="text-align:center;"><s:checkbox id="checkSelecionado" name="selecionados" theme="simple" fieldValue="%{id}"></s:checkbox></td>      
                                    <td> <s:a href="%{urlEditar}"><s:property value="name"/></s:a></td>      
                                    <td> <s:a href="%{urlEditar}"><s:property value="phone"/></s:a></td>      
                             </s:iterator>      
                         </tbody>      
                     </table>      
                     <div id="pager" class="pager">      
                             <img src="<%=request.getContextPath()%>/plugins/jquery/tablesorter/addons/pager/icons/first.png" class="first"/>      
                             <img src="<%=request.getContextPath()%>/plugins/jquery/tablesorter/addons/pager/icons/prev.png" class="prev"/>      
                             <input type="text" class="pagedisplay"/>      
                             <img src="<%=request.getContextPath()%>/plugins/jquery/tablesorter/addons/pager/icons/next.png" class="next"/>      
                             <img src="<%=request.getContextPath()%>/plugins/jquery/tablesorter/addons/pager/icons/last.png" class="last"/>      
                             <select class="pagesize">      
                                 <option selected="selected" value="10">10</option>      
                                 <option value="20">20</option>      
                                 <option value="30">30</option>      
                                 <option value="40">40</option>      
                                 <option value="<s:property value="totalRegistros"/>">todos</option>      
                             </select>      
                             <s:label>Total de registros: <s:property value="totalRegistros"/></s:label>      
                         </form>      

Thanks.

alternatively, you could get the server to return just the html that needs to be inserted into the div rather than the rest of the html document.

I don't really know the TableSorter plugin but I do know that you will need to reinitialize your TableSorter plugin each time you reload the element. so add a line to your success function that targets your table such as

success: function(html) {
    var resultDiv = $("#divResult").replaceWith($('#divResult',     $(html)));
    $('table.tablesorter', resultDiv).TableSorter();

Your problem is on the server side: you have to make a page that returns only the div you want, and then change the 'url' to match that.

Currently you're loading the full page with the AJAX call, which is why it's returning the whole page.

You can use most of the normal jquery ajax function parameters with ajaxSubmit. Just pass in a success function.

$('#formSearch').ajaxSubmit({success: function(){ /* refresh div */ }); 

See here for a more elaborate example.

If you just want to refresh your div with the same static content that was in it before it was overridden by your post results, you can maybe try something like:

$("#Container").html($("#Container").html());

of course be careful that the inner HTML has not changed, or alternatively, you can store the innerHTML in a variable in the document.ready() function, then load it whenever you need to. Sorry, written in haste.

Using jQuery, sometimes when I perform a .get ajax call to update a database, I reload/refresh another part of the page using a simple jQuery .load statement in the success callback function to replace the contents of a div.

$("#div_to_refresh").load("url_of_current_page.html #div_to_refresh")

I'd like to note that this is not the most efficient way to reload a small portion of data, and thus I would only use it on a low traffic web app, but it is simple to code.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.