如标题所述,我正在尝试执行一个简单的任务,当我的 ajax 帖子成功完成我的数据库查询时,我想使用 AJAX 成功选项将“成功”一词添加到空 DIV 中。我不知道如何让该文本出现。任何帮助表示赞赏。谢谢。
这是我的工作 AJAX 帖子:
<script>
$(function(){
$("#noteForm").submit(function(){
// prevent native form submission here
$.ajax({
type: "POST",
data: $('#noteForm').serialize(),
dataType: 'json',
url: "actionpages/link_notes_action.cfm?id=2",
success: function() {
$(".response").append($( "Success" ) );
}
});
return false;
});
});
</script>
我的页面中有一个 div,其 id 为“response”,它嵌套在我表单的 div 中。
<!--- Modal HTML embedded directly into document --->
<div id="LinkNotes#id#" style="display:none;">
<p>These are the notes for: #link_description#</p>
<form id="noteForm">
<textarea id="noteText" name="noteText" cols="45" rows="10">#notes#</textarea><br />
<input name="submit" id="submitForm" type="submit" value="Update"><div class="response" id="response"></div>
<input type="hidden" name="hidden" value="#get_dashboard_links.ID#">
</form>
</div>
最佳答案
这么近!
因为你只想追加一个字符串,你只需要将该字符串传递给.append
.
替换:
.append($( "Success" ) );
与:
.append("Success");
$("Success")
寻找 <Succes />
标记,它找不到,导致附加一个空集。
正如您可能想象的那样,附加“nothing”并没有什么特别的作用 ;-)
关于javascript - AJAX 成功后追加 DIV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25288984/