首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何使用AJAX和jQuery发布django表单

如何使用AJAX和jQuery发布django表单
EN

Stack Overflow用户
提问于 2011-09-07 22:39:38
回答 5查看 105.1K关注 0票数 75

我查阅了大量的django AJAX表单教程,但每个教程都告诉您一种方法,没有一个是简单的,我有点困惑,因为我从来没有使用过AJAX。

我有一个名为" note“的模型,一个用于它的模型形式,在这个模板中,我需要每当note元素发送stop()信号(来自jQuery可排序) django都会更新该对象。

我当前的代码:

views.py

def save_note(request, space_name):

    """
    Saves the note content and position within the table.
    """
    place = get_object_or_404(Space, url=space_name)
    note_form = NoteForm(request.POST or None)

    if request.method == "POST" and request.is_ajax:
        msg = "The operation has been received correctly."          
        print request.POST

    else:
        msg = "GET petitions are not allowed for this view."

    return HttpResponse(msg)

JavaScript:

function saveNote(noteObj) {
    /*
        saveNote(noteObj) - Saves the notes making an AJAX call to django. This
        function is meant to be used with a Sortable 'stop' event.
        Arguments: noteObj, note object.
    */
    var noteID = noteObj.attr('id');

    $.post("../save_note/", {
        noteid: noteID,
        phase: "Example phase",
        parent: $('#' + noteID).parent('td').attr('id'),
        title: $('#' + noteID + ' textarea').val(),
        message: "Blablbla",
    });
}

当前代码从模板中获取数据并将其打印在终端中。我不知道如何处理这些数据。我见过一些人通过jqueryforms来管理数据,以便将数据发送到django。

如何访问AJAX发送的数据并更新note对象?

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7335780

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档