フォームを含む html ページがあり、フォームが正常に送信されたときに、以下の div を表示します。
<div class="response" style="display: none;">
<p>you can download it<a href="{{ link }}">here</a></p>
</div>
jquery関数もあります:
<script type="text/javascript">
$(function() {
$('#sendButton').click(function(e) {
e.preventDefault();
var temp = $("#backupSubmit").serialize();
validateForm();
$.ajax({
type: "POST",
data: temp,
url: 'backup/',
success: function(data) {
$(".response").show();
}
});
});
});
</script>
私のviews.py
(コードビハインド)では、リンクを作成してhtmlページに渡します。私は持っている:
def backup(request):
if request.is_ajax():
if request.method=='POST':
//create a link that user can download a file from it. (link)
variables = RequestContext(request,{'link':link})
return render_to_response('backup.html',variables)
else:
return render_to_response('backup.html')
else:
return render_to_response("show.html", {
'str': "bad Request! :(",
}, context_instance=RequestContext(request))
backup = login_required(backup)
私の問題: ビューが実行されないようです。このページに送信したリンクが表示されません。jQuery関数のみが実行されているようです。よくわかりません。両方を実行するにはどうすればよいですか (つまり、jQuery 関数と、ビューを実行するこの関数に設定した URL を意味します)。
シリアライズ機能の使い方がわかりません。私が検索するたびに、彼らはそれを書きました:
.serialize() メソッドは、標準の URL エンコード表記でテキスト文字列を作成し、"a=1&b=2&c=3&d=4&e=5.
request.Post[「フィールド名」]でフォームフィールドにアクセスできますが、いつ使用する必要があるかわかりません。そして、成功しているデータが何であるかわかりません:私の状況では関数(データ)です。
どうもありがとうございました。