jQuery / Ajax成功函数不会呈现html [英] jQuery/Ajax success function not rendering html
问题描述
我有一个像这样的DIV
这就是我的ajax代码的样子:
var data = $(form#password_forgotten)。serialize();
$ b $ .ajax({
类型:POST,
url:./includes/process_password.php,
data:data,
缓存:false,
成功:函数(响应){
console.log(响应);
$('#message')。html(响应);
}
});
但我无法填充 #message
div与这个阿贾克斯响应。但是,这个ajax编码正在为我工作,这是我可以控制的。
< div class ='alert alert-danger alert-dismissible'role ='alert'>
< strong>糟糕!< / strong>电子邮件地址未被识别请再试一次。
< / div>
有人可以告诉我这有什么问题吗?
谢谢。
现在我发现了我的#message DIV填充,但它隐藏在我的页面中。
像这样 -
糟糕!电子邮件地址无法识别。请尝试另一个
。 ,
总结答案
填充HTML后添加 $('#message')。show()
I have a DIV like this <div id="message"></div>
and trying to add contents to this DIV using Ajax
success.
This is how my ajax code looks like:
var data = $("form#password_forgotten").serialize();
$.ajax({
type: "POST",
url: "./includes/process_password.php",
data: data,
cache: false,
success: function (response) {
console.log(response);
$('#message').html(response);
}
});
But I can not populate #message
div with this ajax response. But this ajax coding is working for me and this is what I can get to console.
<div class='alert alert-danger alert-dismissible' role='alert'>
<strong>Oops!</strong> Email address not recognised. Please try another.
</div>
Can anybody tell me whats the wrong with this?
Thank you.
As per the conversation in the comments
Now I found my #message DIV populating, but its hiding from my page. Like this - Oops! Email address not recognised. Please try another. ,
Summarizing the answer as
After populating the HTML add $('#message').show()
这篇关于jQuery / Ajax成功函数不会呈现html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!