python - Angularjs with Django using AJAX request -
i sent information post method until 1 views in django , returned site. however, i'm not getting submit information on site.
file post3.html
<!doctype html> <html ng-app> <head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.27/angular.min.js"></script> <script> function listdropdown($scope, $http){ $scope.ccvms={lista01:['1','3','5','7','9'],lista02:['2','4','6','8','10']} $scope.send=function(x,y){ $http({ method:'post', url:'/escalar', data:x+y, headers:{'content-type': 'application/x-www-form-urlencoded'}, }).success(function(c){ console.log(c) }) } } </script> </head> <body> <div ng-controller="listdropdown"> <select ng-model="ccvm" ng-options="ccvm ccvm (ccvm, nums) in ccvms"></select> <select ng-model="num" ng-disabled="!ccvm" ng-options="num num in ccvms[ccvm]" ng-change="send(num, ccvm)"></select> <h1 ng-model=c> </div> </body> </html>
file views.py
from django.views.decorators.csrf import csrf_exempt, csrf_protect django.http import httpresponse django.shortcuts import render_to_response def post3(request): return render_to_response("post3.html") @csrf_exempt def escalando(z): x=list(z.post) c=str(x[0])+"_retornou" return httpresponse(c)
file urls.py
from django.conf.urls import patterns, include, url urlpatterns = patterns('', url(r'^post3/','bvmfconsulta.views.post3'), url(r'^escalar','bvmfconsulta.views.escalando'), )
appears in console.log(c) information, example "4lista02_retornou", however, not getting insert on site.
i resolved follows:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.27/angular.min.js"></script> <script> function listdropdown($scope, $http){ $scope.ccvms={lista01:['1','3','5','7','9'],lista02:['2','4','6','8','10']} $scope.resposta="" $scope.send=function(x,y){ $http({ method:'post', url:'/escalar', data:x+y, headers:{'content-type': 'application/x-www-form-urlencoded'}, }).success(function(c){ $scope.resposta=c }) } } </script> <h1 ng-bind="resposta"></h1>
Comments
Post a Comment