私はajaxで動作するページのタブを持っています。3番目のタブ(作成)にはフォームがあります。フォームが送信されたら、最初のタブ(受信トレイ)に移動します。
どうすればいいのか知りたいのですが?私は何をしましたか?私は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>
そして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>
成功関数で何をすべきかわかりません。そして私は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))
したがって、これらのタブを切り替える方法と、vews.pyで何を返す必要があるかを知りたいです。私は本当にあなたの助けが必要です。ありがとう私はdjangoを使用しています