简体   繁体   English

成功时如何在选项卡之间切换

[英]how to switch between tabs when success

I have for tabs in a page which work with ajax. 我在使用ajax的页面中有选项卡。 in the third tab (compose) there is a form, i want when teh form is submitted, then we go to the first tab (inbox). 在第三个选项卡(撰写)中有一个表格,我想要在提交表单时,然后转到第一个选项卡(收件箱)。 在此处输入图片说明

在此处输入图片说明

I want to know how is it possible? 我想知道怎么可能? what have i do? 我该怎么办? i have a base.html: 我有一个base.html:

{% block extrahead %}
    <script type="text/javascript">
        $( document ).ready( function() {
           $( '#inbox' ).html( '{% trans "waiting ..." %}' ).load( 'inbox/');

           $( '#inbox_list' ).click( function() {

               $( '#inbox' ).html( '{% trans "waiting ..." %}' ).load( 'inbox/');
            });
            $( '
                $( '#outbox' ).html( '{% trans "waiting ..." %}' ).load( 'outbox/');
            });
            $( '#compose_list' ).click( function() {

                $( '#compose' ).html( '{% trans "waiting ..." %}' ).load( 'compose/');
            });
            $( '#trash_list' ).click( function() {

                $( '#trash' ).html( '{% trans "waiting ..." %}' ).load( 'trash/');
            });
        });
     </script>

<div id="dRtabs">
            <ul class="tabber">
                <li><a id="inbox_list" href="#inbox">{% trans "inbox" %}</a> </li>
                <li><a id="outbox_list" href="#outbox">{% trans "sent" %}</a> </li>
                <li><a id="compose_list" href="#compose">{%  trans "compose" %}</a> </li>
                <li><a id="trash_list" href="#trash">{%  trans "trash" %}</a> </li>
            </ul>
            <div class="clear"></div>
            <div id="inbox" class="tabContent">
                loading...
            </div>
            <div id="outbox" class="tabContent">
                loading...
            </div>
            <div id="compose" class="tabContent">
                loading...
            </div>
            <div id="trash" class="tabContent">
                loading...
            </div>
    </div>

and in compose.html i have this function: 在compose.html中,我具有以下功能:

<script type="text/javascript">
        $(function() {
            alert("first");
            $('#compose_form').submit(function() {
                alert("second");
                var temp = $("#compose_form").serialize();
                $.ajax({
                    type: "POST",
                    data: temp,
                    url: 'compose/',
                    success: function(data) {
                       ???
                    }
                });
                return false;
            });
        });
    </script>

i don't know what to do in success function. 我不知道该怎么做才能成功。 and i have this view function for compose: 而且我有此视图功能来撰写:

def compose(request, recipient=None):  
    if request.is_ajax():
        if request.method == "POST":
            sender = request.user
            form = ComposeForm(request.POST, recipient_filter=recipient_filter)
            if form.is_valid():
                form.save(sender=request.user)
                messages.info(request, _(u"Message successfully sent."))

                return ???
        else:
            form = ComposeForm()            
        return render_to_response('message/compose.html', {
            'form': form,
            }, context_instance=RequestContext(request))

so i want to know how to switch between these tabs and what i should return in vews.py. 所以我想知道如何在这些选项卡之间切换以及我应该在vews.py中返回什么。 I really need your help. 我真的需要你的帮助。 thanks i'm using django 谢谢,我正在使用django

A simple trigger would work for switching tabs. 一个简单的触发器可用于切换标签。

$('#inbox_list').trigger('click'); // .click() may also work.

You would run this when the form is complete and submitted 您将在表单填写完毕并提交后运行此程序

You can return true of false and you can check this value and if true show him the inbox page, else show him an error message. 您可以返回true或false,可以检查此值,如果为true,则向他显示收件箱页面,否则向他显示错误消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM