簡體   English   中英

AJAX成功后追加DIV

[英]Append DIV after AJAX Success

如標題所示,我試圖執行一個簡單的任務,當我的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>

我的頁面上有一個ID為“ response”的div,它嵌套在表單的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',

從我的腳本修復它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM