admin 管理员组文章数量: 1086019
I really have big difficulties with Ajax, this time I'm not able to append some HTML code to a div.
I need to append to <div id="content-loader"></div>
this HTML string
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:
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
<?php
include("../includes/config.php");
include("../includes/classes.php");
$feed = new feed();
echo $feed->getLogoLoading();
?>
Is there any chance to make it works?
I really have big difficulties with Ajax, this time I'm not able to append some HTML code to a div.
I need to append to <div id="content-loader"></div>
this HTML string
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:
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
<?php
include("../includes/config.php");
include("../includes/classes.php");
$feed = new feed();
echo $feed->getLogoLoading();
?>
Is there any chance to make it works?
Share Improve this question asked Aug 7, 2016 at 23:01 NineCattoRulesNineCattoRules 2,4587 gold badges42 silver badges91 bronze badges 2- Possible duplicate of Load HTML page dynamically into div with jQuery – Ozan Commented Aug 7, 2016 at 23:08
- @Ozan I don't think it's a duplicate, my problem here is related to an Ajax POST – NineCattoRules Commented Aug 7, 2016 at 23:14
1 Answer
Reset to default 4You are getting html in response then simply just put it inside of your content-loader
div using jQuery's html method. like this
success : function(html) {
$('#content-loader').html(html);
本文标签: javascriptHow to append HTML string to div via AjaxStack Overflow
版权声明:本文标题:javascript - How to append HTML string to div via Ajax - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1743998844a2516074.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论