简体   繁体   English

如何通过Ajax将HTML字符串附加到div

[英]How to append HTML string to div via Ajax

I really have big difficulties with Ajax, this time I'm not able to append some HTML code to a div. 我在使用Ajax时确实遇到了很大的困难,这一次我无法将一些HTML代码附加到div上。

I need to append to <div id="content-loader"></div> this HTML string 我需要将此HTML字符串附加到<div id="content-loader"></div>

PHP 的PHP

function getLogo(){
    $logo = '<div class="bg-logo-loading"></div>
            <div class="logo-loading-container">
                <div class="logo-loading-inner">
                    <div class="logo-loading">
                      <div></div>
                      <div></div>
                      <div></div>
                    </div>
                </div>
            </div>';
    return $logo;
}

Using this Ajax POST: 使用此Ajax POST:

JS JS

function showLoader(){
    $.ajax({
        type: "POST",
        url: baseUrl+"/requests/get_Logo.php",
        dataType : 'html',
        cache: false,
        success : function(html){
            $('#content-loader').html($(html.content).text());
        }
    });
}

get_Logo.php get_Logo.php

<?php
include("../includes/config.php");
include("../includes/classes.php");

$feed = new feed();
echo $feed->getLogoLoading();
?>

Is there any chance to make it works? 有机会使其可行吗?

You are getting html in response then simply just put it inside of your content-loader div using jQuery's html method. 您正在获取html作为响应,然后只需使用jQuery的html方法将其放入您的content-loader div中即可。 like this 像这样

success : function(html) {
    $('#content-loader').html(html);

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

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