简体   繁体   English

如何在 Ajax 响应后刷新特定的 div?

[英]How can I refresh a specific div after Ajax response?

The problem is that I want to refresh a specific div after the Ajax response successfully recently I am using:问题是我想在最近使用的 Ajax 响应成功后刷新特定的 div:

$("#parent_div").load(location + "#child_div")

This will refresh whole parent div not specific child_div I have been use these这将刷新整个父 div 而不是特定的child_div我一直在使用这些

$("#parent_div").load(location + "#child_div")
$("#parent_div").reload(location + "#child_div")
$("#child_div").reload(window.location + "#child_div")

Any suggestion regarding this particular issue?关于这个特定问题的任何建议?

AJAX is the art of exchanging data with a server, and updating parts of a web page - without reloading the whole page. AJAX 是与服务器交换数据和更新网页的一部分的艺术 - 无需重新加载整个页面。 This Art comes to life when we were able refer to the tagName of DOM nodes ie, Element .You can allow or restrict any ajax response to be refreshed with this elements.当我们能够引用 DOM 节点的 tagName 即Element时,这项艺术就变得生动起来。您可以允许或限制任何 ajax 响应使用此元素刷新。

<div id="parent_div">
    <span class="parenttexthere">Parent Div Text </span>
    <div id="child_div" >
        <span class="childtexthere">Child Div Text </span>
    </div>
</div>
<br/>
<button> Refresh</button>
<script>
var i=1;
$('button').on('click',function(){
    var data="Parent Div Data Changed "+i+ " times";

    $("#parent_div .parenttexthere").hide().html(data).fadeIn('fast');
    i++;
               });
</script>

Any how this Demo is to specify Elements usage to your example.Where You Can Perform same thing on Ajax call Success.此演示如何为您的示例指定元素用法。您可以在 Ajax 调用成功时执行相同的操作。 Working Demo工作演示

I assume you want to update a specific element on page with response of ajax call(or some manipluation etc).我假设您想使用 ajax 调用(或一些操作等)的响应更新页面上的特定元素。 On ajax success or error event, set the specific element html using methods html or append as shown below:在 ajax 成功或错误事件中,使用方法htmlappend设置特定元素 html,如下所示:

 jQuery("#myelement").html("Ajax response came as success");

or if you want to append then:或者如果你想追加那么:

 jQuery("#myelement").append("Ajax response came as success");

here the html, append word will replace the element content with the content you provided as string ("Ajax response came as success").这里的 html, append word 将用您作为字符串提供的内容替换元素内容(“Ajax 响应成功”)。 The content can inculde html div or simple text .内容可以包括 html div 或简单的文本。 Here in example "myelement" is id of the html element.在示例中,“myelement”是 html 元素的 id。

For example:例如:

 <div id="myelement"></div>
$("#child_div").load(location + "#parent_div")

要加载特定的 div,请在第一部分添加您需要刷新的 div(即我添加子 div 的地方),现在 load 是一个加载页面的函数,其中 location 表示当前位置,父 div 是页面的内容加载

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

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