AJAX成功后追加DIV

Append DIV after AJAX Success

本文关键字:DIV 追加 成功 AJAX      更新时间:2023-09-26

正如标题所述,我正在尝试执行一个简单的任务,当我的ajax帖子成功完成我的数据库查询时,我想使用ajax成功选项将单词"Success"添加到空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"并没有特别大的作用;-)

我从这篇文章中找到了答案

明显删除

dataType: 'json',