jQuery JSON 解析并附加数据到不同的位置


jQuery JSON parse and apend data on different placement

我有一个页面,我想在不同的位置展示和刷新不同的广告。我通过 AJAX 成功从 PHP 文件获得响应,但无法将它们附加到特定位置。

网页代码

<script>var ads = [];</script>
<div id="ad-728x90">fhhfgh</div>
<!-- Page Content -->
<div class="container">
    <!-- Heading Row -->
    <div class="row">
        <div class="col-md-8">
            <img class="img-responsive img-rounded" src="http://placehold.it/900x350" alt="">
        </div>
        <!-- /.col-md-8 -->
        <div class="col-md-4">
            <h1>Business Name or Tagline</h1>
            <p>This is a template that is great for small businesses. It doesn't have too much fancy flare to it, but it makes a great use of the standard Bootstrap core components. Feel free to use this template for any project you want!</p>
            <a class="btn btn-primary btn-lg" href="#">Call to Action!</a>
        </div>
        <!-- /.col-md-4 -->
    </div>
    <!-- /.row -->
    <hr>
    <!-- Call to Action Well -->
    <div class="row">
        <div class="col-lg-12">
            <div class="well text-center">
                This is a well that is a great spot for a business tagline or phone number for easy access!
            </div>
            <div id="ad-300x250" class="ads"></div>
        </div>
        <!-- /.col-lg-12 -->
    </div>
    <!-- /.row -->

Javascript/jQuery code

<script type="text/javascript">ads.push("728x90", "300x250");</script>
<script>
$(document).ready(function()
{
    function loadAds()
    {
        $.post('ads.php', { adID: ads }, function (e) {
            if (e.status == 'error')
            {
                $('.ads').each(function ()
                {
                    $(this).remove();
                });
            }
            else if (e.status == 'ok')
            {
                var data = e.data;
                $.each(data, function (adID)
                {
                    $('#ad-' + adID).find('.ads').html();
                });
            }
        }, 'json');
    }
    loadAds();
});
</script>

JSON 响应:

{"状态":"

ok","data":{"728x90":"''r'''t''r'''t''t''r'''t''t''t

728x90 ads

''r'''t''t
''r'''t ","300x250":"''r'''t''r'''t''t'''t''t 300x250 ads ''r'''t''t ''

r'''t "}}

以下内容应将数据放在正确的 id 中

$.each(data, function (adID, adHtml){
      $('#ad-' + adID).html(adHtml);
});

有问题的 html 没有显示任何具有类ads的孩子 <div id="ad-728x90">因此find('.ads')被删除

如果这不起作用,问题需要澄清预期结果