From b9c6451f88caa35ab39b6468a99b147d7d7f4937 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 20 Mar 2011 15:51:02 -0500 Subject: Fix news preview with CSRF and AJAX in Django 1.2.5 Signed-off-by: Dan McGee --- media/archweb.js | 14 ++++++++------ templates/news/add.html | 8 ++++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/media/archweb.js b/media/archweb.js index 52e817a4..03358fa9 100644 --- a/media/archweb.js +++ b/media/archweb.js @@ -71,16 +71,18 @@ if (typeof $.tablesorter !== 'undefined') { /* news/add.html */ function enablePreview() { - $('#previewbtn').click(function(event) { + $('#news-preview-button').click(function(event) { event.preventDefault(); - $.post('/news/preview/', - { data: $('#id_content').val() }, + $.post('/news/preview/', { + data: $('#id_content').val(), + csrfmiddlewaretoken: $('#newsform input[name=csrfmiddlewaretoken]').val() + }, function(data) { - $('#previewdata').html(data); - $('.news-article').show(); + $('#news-preview-data').html(data); + $('#news-preview').show(); } ); - $('#previewtitle').html($('#id_title').val()); + $('#news-preview-title').html($('#id_title').val()); }); } diff --git a/templates/news/add.html b/templates/news/add.html index f580e0d0..bb866dc4 100644 --- a/templates/news/add.html +++ b/templates/news/add.html @@ -23,14 +23,14 @@

News: Add Article

- +

-