File tree 2 files changed +21
-5
lines changed
2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change 2
2
from django .template import RequestContext
3
3
from django .views .decorators .csrf import csrf_exempt
4
4
from comment_react .models import Comments
5
+ from django .http import HttpResponse
6
+ import json
5
7
6
8
@csrf_exempt
7
9
def home (request ):
@@ -16,6 +18,7 @@ def home(request):
16
18
"post_id" : obj .post_id ,
17
19
}
18
20
comments .append (commentCurr )
21
+ comments .append ({ 'status_code' : 'success' })
19
22
return render_to_response ('index.html' , comments )
20
23
elif request .method == 'POST' :
21
24
data = request .POST .urlencode ()
@@ -36,8 +39,10 @@ def home(request):
36
39
"post_id" : obj .post_id ,
37
40
}
38
41
comments .append (commentCurr )
42
+ comments .append ({ 'status_code' : 'success' })
39
43
return render_to_response ('index.html' , comments )
40
44
45
+ @csrf_exempt
41
46
def getComments (request ):
42
47
data = Comments .objects .all ()
43
48
comments = []
@@ -48,7 +53,7 @@ def getComments(request):
48
53
"post_id" : obj .post_id ,
49
54
}
50
55
comments .append (commentCurr )
51
- print comments
52
- return render_to_response ( 'index.html' , comments )
56
+ comments . append ({ 'status_code' : 'success' })
57
+ return HttpResponse ( json . dumps ( comments ), content_type = "application/json" )
53
58
54
59
Original file line number Diff line number Diff line change 1
1
{% load staticfiles %}
2
2
< link rel ="stylesheet " type ="text/css " href ="{% static 'css/style.css' %} ">
3
-
4
3
< div id ="content "> </ div >
5
4
< script src ="http://code.jquery.com/jquery-1.10.0.min.js "> </ script >
6
5
< script type ="text/jsx ">
7
6
/** @jsx React.DOM */
8
7
var CommentBox = React . createClass ( {
9
8
getInitialState : function ( ) {
9
+ // $.ajax({
10
+ // url : "getcomments/",
11
+ // type : "POST",
12
+ // success : function(data) {
13
+ // console.log('success - '+ JSON.stringify(data));
14
+ // return data;
15
+ // },
16
+ // error : function(xhr,errmsg,err) {
17
+ // console.log('err');
18
+ // console.log(xhr.status + ": " + xhr.responseText);
19
+ // return {data: []};
20
+ // }
21
+ // });
10
22
return { data : [ ] } ;
11
23
} ,
12
24
loadCommentsFromServer : function ( ) {
16
28
success : function ( data ) {
17
29
console . log ( 'in - ' + data ) ;
18
30
this . setState ( { data : data } ) ;
19
- console . log ( 'data - ' + data ) ;
20
31
} . bind ( this ) ,
21
32
error : function ( xhr , status , err ) {
22
33
console . log ( 'out' ) ;
@@ -110,7 +121,7 @@ <h1>Comments</h1>
110
121
}
111
122
} ) ;
112
123
React . renderComponent (
113
- < CommentBox url = "" pollInterval = { 2000 } /> ,
124
+ < CommentBox url = "getcomments/ " pollInterval = { 2000 } /> ,
114
125
document . getElementById ( 'content' )
115
126
) ;
116
127
</ script >
You can’t perform that action at this time.
0 commit comments